Bha*_*ani 5 java selenium dependencies maven
我正在尝试在Maven项目中使用Selenium的最新版本3.4.0。我使用以下依赖项导入了所有Selenium的jar:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
问题是我无法在Eclipse中的主要方法中的以下代码中解决我项目中的任何依赖项:-
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");
}
}
Run Code Online (Sandbox Code Playgroud)
我想念什么?Eclipse无法将FirefoxDriver类型解析为任何依赖项。请帮忙。
要使用Selenium 3.4.0和Mozilla Firefox 53.x,您需要从此处下载最新的geckodriver v0.16.1 。将其保存在您的计算机中,并在代码中提供geckodriver的绝对路径。
确保已使用所需的依赖关系更新了pom.xml,如下所示:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
建议使用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");
Run Code Online (Sandbox Code Playgroud)
提供以下命令来清除以前的依赖关系,安装新的依赖关系并执行测试:
>mvn clean
>mvn install
>mvn test
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35425 次 |
| 最近记录: |