Java Selenium错误:线程“main”中出现异常java.lang.NoClassDefFoundError:组织/openqa/selenium/有身份验证,智能J IDEA

kb5ga3dv  于 2022-12-03  发布在  Java
关注(0)|答案(1)|浏览(360)

我只是尝试使用IntelliJ IDE运行一个基本的webdriver程序,但在运行时出现以下所有错误:

"C:\Program Files\Java\jdk-19\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.2.3\lib\idea_rt.jar=59762:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.2.3\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\roone\IdeaProjects\WebDriverDemo\target\classes;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-java\4.0.0-beta-4\selenium-java-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\4.0.0-beta-4\selenium-chrome-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\com\google\auto\service\auto-service-annotations\1.0\auto-service-annotations-1.0.jar;C:\Users\roone\.m2\repository\com\google\auto\service\auto-service\1.0\auto-service-1.0.jar;C:\Users\roone\.m2\repository\com\google\auto\auto-common\1.0\auto-common-1.0.jar;C:\Users\roone\.m2\repository\com\google\guava\guava\30.1.1-jre\guava-30.1.1-jre.jar;C:\Users\roone\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\roone\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\roone\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\roone\.m2\repository\org\checkerframework\checker-qual\3.8.0\checker-qual-3.8.0.jar;C:\Users\roone\.m2\repository\com\google\errorprone\error_prone_annotations\2.5.1\error_prone_annotations-2.5.1.jar;C:\Users\roone\.m2\repository\com\google\j2objc\j2objc-annotations\1.3\j2objc-annotations-1.3.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-chromium-driver\4.0.0-beta-4\selenium-chromium-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-devtools\4.0.0-beta-4\selenium-devtools-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-http\4.0.0-beta-4\selenium-http-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-json\4.0.0-beta-4\selenium-json-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v85\4.0.0-beta-4\selenium-devtools-v85-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v88\4.0.0-beta-4\selenium-devtools-v88-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v89\4.0.0-beta-4\selenium-devtools-v89-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v90\4.0.0-beta-4\selenium-devtools-v90-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v91\4.0.0-beta-4\selenium-devtools-v91-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-edge-driver\4.0.0-beta-4\selenium-edge-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\4.0.0-beta-4\selenium-firefox-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-firefox-xpi-driver\4.0.0-beta-4\selenium-firefox-xpi-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\4.0.0-beta-4\selenium-ie-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-opera-driver\4.0.0-beta-4\selenium-opera-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\4.0.0-beta-4\selenium-remote-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\com\beust\jcommander\1.81\jcommander-1.81.jar;C:\Users\roone\.m2\repository\io\netty\netty-buffer\4.1.63.Final\netty-buffer-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-codec-http\4.1.63.Final\netty-codec-http-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-codec\4.1.63.Final\netty-codec-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-handler\4.1.63.Final\netty-handler-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-common\4.1.63.Final\netty-common-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-transport-native-epoll\4.1.63.Final\netty-transport-native-epoll-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-transport-native-kqueue\4.1.63.Final\netty-transport-native-kqueue-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-transport-native-unix-common\4.1.63.Final\netty-transport-native-unix-common-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-transport\4.1.63.Final\netty-transport-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-resolver\4.1.63.Final\netty-resolver-4.1.63.Final.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-api\1.2.0\opentelemetry-api-1.2.0.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-context\1.2.0\opentelemetry-context-1.2.0.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-exporter-logging\1.2.0\opentelemetry-exporter-logging-1.2.0.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-sdk-metrics\1.2.0-alpha\opentelemetry-sdk-metrics-1.2.0-alpha.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-sdk-common\1.2.0\opentelemetry-sdk-common-1.2.0.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-sdk-extension-autoconfigure\1.2.0-alpha\opentelemetry-sdk-extension-autoconfigure-1.2.0-alpha.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-sdk-trace\1.2.0\opentelemetry-sdk-trace-1.2.0.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-api-metrics\1.2.0-alpha\opentelemetry-api-metrics-1.2.0-alpha.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-sdk\1.2.0\opentelemetry-sdk-1.2.0.jar;C:\Users\roone\.m2\repository\io\opentelemetry\opentelemetry-semconv\1.2.0-alpha\opentelemetry-semconv-1.2.0-alpha.jar;C:\Users\roone\.m2\repository\io\ous\jtoml\2.0.0\jtoml-2.0.0.jar;C:\Users\roone\.m2\repository\net\bytebuddy\byte-buddy\1.11.0\byte-buddy-1.11.0.jar;C:\Users\roone\.m2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;C:\Users\roone\.m2\repository\org\asynchttpclient\async-http-client\2.12.3\async-http-client-2.12.3.jar;C:\Users\roone\.m2\repository\org\asynchttpclient\async-http-client-netty-utils\2.12.3\async-http-client-netty-utils-2.12.3.jar;C:\Users\roone\.m2\repository\io\netty\netty-codec-socks\4.1.60.Final\netty-codec-socks-4.1.60.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-handler-proxy\4.1.60.Final\netty-handler-proxy-4.1.60.Final.jar;C:\Users\roone\.m2\repository\io\netty\netty-transport-native-epoll\4.1.60.Final\netty-transport-native-epoll-4.1.60.Final-linux-x86_64.jar;C:\Users\roone\.m2\repository\io\netty\netty-transport-native-kqueue\4.1.60.Final\netty-transport-native-kqueue-4.1.60.Final-osx-x86_64.jar;C:\Users\roone\.m2\repository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;C:\Users\roone\.m2\repository\com\typesafe\netty\netty-reactive-streams\2.0.4\netty-reactive-streams-2.0.4.jar;C:\Users\roone\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;C:\Users\roone\.m2\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-safari-driver\4.0.0-beta-4\selenium-safari-driver-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-support\4.0.0-beta-4\selenium-support-4.0.0-beta-4.jar;C:\Users\roone\.m2\repository\org\seleniumhq\selenium\selenium-api\3.141.59\selenium-api-3.141.59.jar com.pluralsight.WebDriverDemo
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/HasAuthentication
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at com.pluralsight.WebDriverDemo.main(WebDriverDemo.java:11)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.HasAuthentication
    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:521)
    ... 19 more

Process finished with exit code 1

正如我在网上或其他类似的线程中所读到的,这应该是由于缺乏chrome的身份验证。我尝试了不同的方法,但没有一个工作。我的WebDriverDemo.java文件:

package com.pluralsight;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class WebDriverDemo {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("http://google.com");

    }
}

我的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.pluralsight</groupId>
    <artifactId>WebDriverDemo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
    <maven.compiler.release>1.11</maven.compiler.release>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0-beta-4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
        </plugins>
    </build>

</project>

任何帮助将不胜感激。谢谢

9rygscc1

9rygscc11#

我认为这个错误可能与您没有指定chromedriver版本有关。我建议使用驱动程序管理器。将此依赖项添加到pom.xml

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.1.0</version>
    <scope>compile</scope>
</dependency>

然后在您的WebDriverDemo.java文件中,您可以如下启动webdriver:

WebDriverManager.chromedriver().driverVersion("100.0.4896.60").setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");

版本可能需要更新,此代码是从我的一个旧项目复制的。
此外,这可能是一个问题,因为您使用的是http,而不是https的链接,我记得这导致的问题以及。

相关问题