为什么我无法使用 Selenium 进行连接,而 Java 使用 Maven 依赖项?

Why I can't to connect using Selenium and Java using Maven dependency?

我正在尝试将 seleium 连接到 maven java 项目。 我得到错误。驱动程序已上传并在项目中找到

我的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>