java - 使用 selenium 启动 Microsoft Edge Chromium 浏览器

标签 java selenium

我正在尝试使用 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.

ma​​ven 依赖

<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/

相关文章:

java - cucumber 无法解析为类型

java - 为对象创建定义的值

java - boolean 值字符串到数组?

java - 使用 Excel 将多个参数添加到 Drools 规则决策表中的操作

java - 在不同的浏览器 session 中运行测试,但始终得到 'NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?'

python - 从 Selenium 导入 webdriver 不工作?

java - JPA 连接查询不起作用

java - 如何在测试的拆卸方法中获取 junit 断言失败原因

javascript - Protractor - 上传文件错误 "Element &lt;input type="文件">在 Firefox 58 中无法通过键盘访问,但在 Firefox 57 中工作正常

python - pytest 自动化显然在测试收集阶段运行测试