Skip to content

Instantly share code, notes, and snippets.

@wootiml33t
Last active April 4, 2019 15:34
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 wootiml33t/e9e94f382fc07486daabe3c098e5caa2 to your computer and use it in GitHub Desktop.
Save wootiml33t/e9e94f382fc07486daabe3c098e5caa2 to your computer and use it in GitHub Desktop.
How to start Microsoft Edge with Java
package com.company;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.File;
import java.io.IOException;
public class Main {
private static EdgeDriverService service;
private static WebDriver driver;
private static void createAndStartService() {
try {
service = new EdgeDriverService.Builder()
.usingDriverExecutable(new File("C:\\Windows\\SysWOW64\\MicrosoftWebDriver.exe")) //Using the Windows feature on demand version
.usingAnyFreePort()
.build();
service.start();
}
catch (IOException e) {
//
}
}
private static void init() {
createAndStartService();
driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.edge());
}
public static void main(String[] args) {
init();
driver.get("https://www.microsoft.com/en-us/");
driver.quit();
service.stop(); //Need to stop the service otherwise an exception will be thrown on next run. Issue is mitigated by just running again.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment