【问题标题】:Why I can't to connect using Selenium and Java using Maven dependency?为什么我无法使用 Maven 依赖项使用 Selenium 和 Java 进行连接?
【发布时间】:2022-01-24 07:53:26
【问题描述】:

我正在尝试将 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)

我没有做什么?

【问题讨论】:

    标签: java selenium maven firefox geckodriver


    【解决方案1】:

    您可能希望使用最新且稳定的 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>
    

    【讨论】:

    • 非常感谢。此外,我还需要添加浏览器依赖项。它有效
    • @ДимаВасильев 浏览器依赖项的错误会有所不同。您已明确提到驱动程序已上传并位于项目中。很高兴能为您提供帮助。请accept answer 点击我的 answer 旁边的空心刻度线,该刻度线就在 votedown 箭头下方,这样刻度线就会转动绿色.
    【解决方案2】:

    我的解决方案:

    如果我使用 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-03
      • 2012-05-18
      • 2018-01-21
      • 2017-12-07
      • 1970-01-01
      • 2016-11-04
      • 2022-11-27
      • 2017-02-14
      相关资源
      最近更新 更多