[英]Launch Microsoft Edge Chromium browser using selenium
I am trying to launch Microsoft Edge Chromium browser using selenium.我正在尝试使用 selenium 启动 Microsoft Edge Chromium 浏览器。 Microsoft Edge chromium Version: Version 79.0.309.65 (Official Build) (64-bit) Downloading driver file from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Microsoft Edge 铬版本:版本 79.0.309.65(官方版本)(64 位)从https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/下载驱动程序文件
Using this code to for the same but it is giving unreachable browser Exception and not working.使用此代码进行相同的操作,但它给出了无法访问的浏览器异常并且无法正常工作。
1.System.setProperty("webdriver.edge.driver", "C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedgedriver.exe");
EdgeOptions options = new EdgeOptions();
BROWSER=properties.getProperty("BrowserName");
options.setCapability(BROWSER, false);
//DesiredCapabilities m_capability = DesiredCapabilities.edge();
driver= new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
2.DesiredCapabilities m_capability = DesiredCapabilities.chrome();
BROWSER=properties.getProperty("BrowserName");`enter code here`
m_capability.setCapability( BROWSER, "chrome" );
driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver",
"C:\\edgedriver_win64-1\\msedgedriver.exe");
It is looking like compatibility issue.它看起来像兼容性问题。 You can upgrade or downgrade your
msedgedriver
driver version to make it work.您可以升级或降级
msedgedriver
驱动程序版本以使其正常工作。
I will recommend you to use WebDriverManager
我会推荐你使用
WebDriverManager
WebDriverManager allows to automate the management of the binary drivers (eg chromedriver, geckodriver, etc.) required by Selenium WebDriver.
WebDriverManager 允许自动管理 Selenium WebDriver 所需的二进制驱动程序(例如 chromedriver、geckodriver 等)。
maven dependency Maven 依赖
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
Once we have included this dependency, you can let WebDriverManager to manage the WebDriver binaries for you.一旦我们包含了这个依赖项,您就可以让 WebDriverManager 为您管理 WebDriver 二进制文件。 Now you can set driver instance for Edge.
现在您可以为 Edge 设置驱动程序实例。
public class EdgeDevTest {
private WebDriver driver;
@BeforeClass
public static void setupClass() {
WebDriverManager.edgedriver().setup();
}
@Before
public void setupTest() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(
"C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
EdgeOptions edgeOptions = new EdgeOptions().merge(chromeOptions);
driver = new EdgeDriver(edgeOptions);
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
public void testservice(){
EdgeOptions opt= new EdgeOptions();
opt.setHeadless();
WebDriver driver= new EdgeDriver(opt);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.