为什么我不能使用 Selenium 和 Java 使用 Maven 依赖项进行连接?



我正在尝试将seleium连接到mavenjava项目。我犯了错误。驱动程序已上传并位于项目中

我的Main.java

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Main {
public static void main(String[] args) throws Exception{
System.setProperty("webdriver.gecko.driver", "C:\Users\Vlad\IntellijIDEAProjects\VKParser\geckodriver.exe");
WebDriver wd = new FirefoxDriver();
}
}

此外,我的依赖

<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>

我的错误

Exception in thread "main" java.lang.NoSuchMethodError: 'int org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHashedWheelTimerTickDuration()'
at org.openqa.selenium.remote.http.netty.NettyClient.<clinit>(NettyClient.java:56)
at org.openqa.selenium.remote.http.netty.NettyClient$Factory.createClient(NettyClient.java:146)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:107)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:94)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:85)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:80)
at org.openqa.selenium.firefox.FirefoxDriver$FirefoxDriverCommandExecutor.<init>(FirefoxDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:232)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:164)
at Main.main(Main.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

我没有做什么?

您可能喜欢使用最新且稳定的Selenium Java工件,如下所示:

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.1</version>
</dependency>

我的解决方案:

如果我使用firefox,那么我会为它添加依赖项

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>4.1.1</version>
</dependency>

最新更新