我正在尝试在 Maven 项目中使用 Selenium 的最新版本 3.4.0。我使用以下依赖项导入了所有 Selenium 的罐子:-
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
问题是我无法在 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");
}
}
我错过了什么? Eclipse 无法将 FirefoxDriver 类型解析为任何依赖项。请帮忙。
原文由 Bharat Nanwani 发布,翻译遵循 CC BY-SA 4.0 许可协议
要使用 Selenium 3.4.0 和 Mozilla Firefox 53.x,您需要从 此处 下载最新的 geckodriver v0.16.1。将其保存在您的机器中并在您的代码中提供 geckodriver 的绝对路径。
确保您已使用所需的依赖项更新 pom.xml,如下所示:
建议使用
WebDriver
接口,而不是使用FirefoxDriver
实现。您的代码将如下所示:
提供以下命令以清除以前的依赖项,安装新的依赖项并执行测试: