Last active
April 4, 2019 15:34
-
-
Save wootiml33t/e9e94f382fc07486daabe3c098e5caa2 to your computer and use it in GitHub Desktop.
How to start Microsoft Edge with Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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