我正在尝试使用 selenium 启动 Microsoft Edge Chromium 浏览器。 Microsoft Edge chromium 版本:版本 79.0.309.65(官方版本)(64 位) 从 https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ 下载驱动程序文件
使用此代码可以实现相同的目的,但它会给出无法访问的浏览器异常并且不起作用。
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");
最佳答案
看起来像是兼容性问题。您可以升级或降级 msedgedriver
驱动程序版本以使其正常工作。
我会推荐您使用WebDriverManager
WebDriverManager allows to automate the management of the binary drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium WebDriver.
maven 依赖
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
一旦我们包含了此依赖项,您就可以让 WebDriverManager 为您管理 WebDriver 二进制文件。现在您可以为 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();
}
}
关于java - 使用 selenium 启动 Microsoft Edge Chromium 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59767547/