我在我的 pom.xml 中添加了最新的 Selenium 依赖项
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.1</version>
</dependency>
我使用 pom.xml 在目录中运行了 mvn clean install 并且我还根据 Selenium 文档在我的应用程序类中导入了正确的类
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
但是,当我尝试运行我的主要方法时,出现以下错误
Exception in thread "main" java.lang.NoClassDefFoundError:
org/openqa/selenium/WebDriver
我查看了 ~/.m2/repository 文件夹,但没有看到 openqa 文件夹,而是看到了 seleniumhq 文件夹。
为什么 maven 没有安装 openqa 文件夹,为什么文档说要从 org.openqa 导入…而我的 jar 存储库中根本不存在。我很困惑,我只想在我的本地存储库中成功导入 selenium Webdriver。
原文由 nivo1000 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 Eclipse IDE 中遇到此错误。在 Eclipse 中转到项目属性,在 Java 构建路径中只需在类路径而不是模块路径中添加硒罐。然后在顶部的“项目”选项卡下执行“清理”以删除早期的 buiid,然后执行“运行”。