Skip to content

Instantly share code, notes, and snippets.

@nagasama
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagasama/f6dd1aeb6da190f7e22f to your computer and use it in GitHub Desktop.
Save nagasama/f6dd1aeb6da190f7e22f to your computer and use it in GitHub Desktop.
Selenium Edge Sample
package samples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.edge.*;
import org.openqa.selenium.remote.Augmenter;
public class SeleniumEdgeSample1Test {
private WebDriver driver;
private String baseUrl;
@Before
public void setUp() throws Exception {
EdgeOptions options = new EdgeOptions();
options.setPageLoadStrategy("eager");
driver = new EdgeDriver(options);
baseUrl = "http://www.microsoft.com/ja-jp/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testResult() throws Exception {
driver.get(baseUrl);
capture(driver,Paths.get("."),"resut.png");
}
@After
public void tearDown() throws Exception {
driver.quit();
}
public static void capture(WebDriver driver, Path captureDirectory, String fileName) {
WebDriver tempdriver = driver;
if (!(driver instanceof TakesScreenshot)) {
tempdriver = new Augmenter().augment(driver);
}
TakesScreenshot screen = (TakesScreenshot) tempdriver;
Path capture = captureDirectory.resolve(fileName);
try {
Files.write(capture, screen.getScreenshotAs(OutputType.BYTES));
} catch (IOException e) {
e.printStackTrace();
}
}
}
@uila-jay
Copy link

It doesn't work and some error message:
EdgeOptions options = new EdgeOptions();
options.setPageLoadStrategy("eager");
driver = new EdgeDriver(options);
Error:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.edge.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver. The latest version can be downloaded from http://go.microsoft.com/fwlink/?LinkId=619687
or:
org.openqa.selenium.UnsupportedCommandException: Unknown command received...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment