如何使用Maven使用Selenium 3.4.0启动FireFoxDriver? [英] How to start FireFoxDriver using Selenium 3.4.0 using Maven?
问题描述
我正在尝试在maven项目中使用Selenium的最新版本3.4.0。我使用以下依赖项导入了所有Selenium的罐子: -
I am trying to use Selenium's latest version 3.4.0 in a maven project. I imported all Selenium's jars using below dependency:-
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
问题是我无法解决Eclipse中我的项目中的任何依赖关系,以获取main方法中的以下代码: -
The problem is I am unable to resolve any dependency in my project in Eclipse for below code inside main method:-
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类型解析为任何依赖项。请帮忙。
What am I missing? Eclipse is unable to resolve FirefoxDriver type to any dependencies. Please help.
推荐答案
使用Selenium 3.4.0& Mozilla Firefox 53.x您需要从此处下载最新的geckodriver v0.16.1。将它保存在您的机器中在代码中提供geckodriver的绝对路径。
To work with Selenium 3.4.0 & Mozilla Firefox 53.x you need to download the latest geckodriver v0.16.1 from here. Save it in your machine & provide absolute path of the geckodriver in your code.
确保已使用所需的依赖关系更新pom.xml,如下所示:
Ensure that you have updated the pom.xml with the required dependency as follows:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
建议使用 WebDriver
界面而不是使用 FirefoxDriver
实现。
It is recommended to use the WebDriver
interface rather than to use the FirefoxDriver
implementation.
您的代码如下所示:
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");
提供以下命令以清除先前的依赖关系,安装新的依赖关系&执行测试:
Provide the following commands to flush out the previous dependencies, install the new dependencies & execute your test:
>mvn clean
>mvn install
>mvn test
这篇关于如何使用Maven使用Selenium 3.4.0启动FireFoxDriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!