在selenium中运行与打开chrome浏览器相关的代码时遇到错误

问题描述 投票:0回答:1

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: dev/failsafe/Policy
    at org.seleniumhq.selenium.http/org.openqa.selenium.remote.http.ClientConfig.<clinit>(ClientConfig.java:33)
    at org.seleniumhq.selenium.chrome_driver/org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
    at org.seleniumhq.selenium.chrome_driver/org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:51)
    at First/test.Dashboard.main(Dashboard.java:11)
Caused by: java.lang.ClassNotFoundException: dev.failsafe.Policy
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
    ... 4 more

尝试启动chrome浏览器抛出selenium WebDriver,它有POM来测试TestNG

java selenium-webdriver pom.xml
1个回答
0
投票

在maven中添加Failsafe依赖:

<dependency>
    <groupId>net.jodah</groupId>
    <artifactId>failsafe</artifactId>
    <version>2.4.3</version>
</dependency>

确保 Selenium 依赖项是最新的:

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

更新

WebDriver
ChromeDriver
并确保它与您安装的 Chrome 版本匹配。

WebDriver
二进制添加到代码中的路径或使用
WebDriverManager

© www.soinside.com 2019 - 2024. All rights reserved.