微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用Maven使用Selenium 3.4.0启动FireFoxDriver?

我正在尝试在maven项目中使用Selenium的最新版本3.4.0.我使用以下依赖项导入了所有Selenium的罐子: –

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.4.0</version>
</dependency>

问题是我无法解决Eclipse中我的项目中的任何依赖关系,以获取main方法中的以下代码: –

public class FirefoxTest {

    public static void main(String[] args) {
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine

        FirefoxDriver driver = new FirefoxDriver(options);
        driver.get("http://www.google.com");
    }
}

我错过了什么? Eclipse无法将FirefoxDriver类型解析为任何依赖项.请帮忙.

解决方法:

使用Selenium 3.4.0& Mozilla Firefox 53.x需要从here下载最新的geckodriver v0.16.1.将其保存在您的机器和放大器中.在代码中提供geckodriver的绝对路径.

确保已使用所需的依赖关系更新pom.xml,如下所示:

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
</dependency> 

建议使用WebDriver接口而不是使用FirefoxDriver实现.

您的代码将如下所示:

    System.out.println("Welcome to Maven World");
    System.setProperty("webdriver.gecko.driver", "C:\\Utility\\browserDrivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();       
    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    driver.navigate().to("http://www.google.com");

提供以下命令以清除以前的依赖项,安装新的依赖项&执行你的测试:

>mvn clean
>mvn install
>mvn test 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐