我只是想使用IntelliJ IDE运行一个基本的webdriver程序,但我在运行时得到所有这些错误:
"C:Program FilesJavajdk-19binjava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2022.2.3libidea_rt.jar=59762:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2022.2.3bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:UsersrooneIdeaProjectsWebDriverDemotargetclasses;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-java4.0.0-beta-4selenium-java-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-chrome-driver4.0.0-beta-4selenium-chrome-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositorycomgoogleautoserviceauto-service-annotations1.0auto-service-annotations-1.0.jar;C:Usersroone.m2repositorycomgoogleautoserviceauto-service1.0auto-service-1.0.jar;C:Usersroone.m2repositorycomgoogleautoauto-common1.0auto-common-1.0.jar;C:Usersroone.m2repositorycomgoogleguavaguava30.1.1-jreguava-30.1.1-jre.jar;C:Usersroone.m2repositorycomgoogleguavafailureaccess1.0.1failureaccess-1.0.1.jar;C:Usersroone.m2repositorycomgoogleguavalistenablefuture9999.0-empty-to-avoid-conflict-with-guavalistenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:Usersroone.m2repositorycomgooglecodefindbugsjsr3053.0.2jsr305-3.0.2.jar;C:Usersroone.m2repositoryorgcheckerframeworkchecker-qual3.8.0checker-qual-3.8.0.jar;C:Usersroone.m2repositorycomgoogleerrorproneerror_prone_annotations2.5.1error_prone_annotations-2.5.1.jar;C:Usersroone.m2repositorycomgooglej2objcj2objc-annotations1.3j2objc-annotations-1.3.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-chromium-driver4.0.0-beta-4selenium-chromium-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-devtools4.0.0-beta-4selenium-devtools-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-http4.0.0-beta-4selenium-http-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-json4.0.0-beta-4selenium-json-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-devtools-v854.0.0-beta-4selenium-devtools-v85-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-devtools-v884.0.0-beta-4selenium-devtools-v88-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-devtools-v894.0.0-beta-4selenium-devtools-v89-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-devtools-v904.0.0-beta-4selenium-devtools-v90-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-devtools-v914.0.0-beta-4selenium-devtools-v91-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-edge-driver4.0.0-beta-4selenium-edge-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-firefox-driver4.0.0-beta-4selenium-firefox-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-firefox-xpi-driver4.0.0-beta-4selenium-firefox-xpi-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-ie-driver4.0.0-beta-4selenium-ie-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-opera-driver4.0.0-beta-4selenium-opera-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-remote-driver4.0.0-beta-4selenium-remote-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositorycombeustjcommander1.81jcommander-1.81.jar;C:Usersroone.m2repositoryionettynetty-buffer4.1.63.Finalnetty-buffer-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-codec-http4.1.63.Finalnetty-codec-http-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-codec4.1.63.Finalnetty-codec-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-handler4.1.63.Finalnetty-handler-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-common4.1.63.Finalnetty-common-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-transport-native-epoll4.1.63.Finalnetty-transport-native-epoll-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-transport-native-kqueue4.1.63.Finalnetty-transport-native-kqueue-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-transport-native-unix-common4.1.63.Finalnetty-transport-native-unix-common-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-transport4.1.63.Finalnetty-transport-4.1.63.Final.jar;C:Usersroone.m2repositoryionettynetty-resolver4.1.63.Finalnetty-resolver-4.1.63.Final.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-api1.2.0opentelemetry-api-1.2.0.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-context1.2.0opentelemetry-context-1.2.0.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-exporter-logging1.2.0opentelemetry-exporter-logging-1.2.0.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-sdk-metrics1.2.0-alphaopentelemetry-sdk-metrics-1.2.0-alpha.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-sdk-common1.2.0opentelemetry-sdk-common-1.2.0.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-sdk-extension-autoconfigure1.2.0-alphaopentelemetry-sdk-extension-autoconfigure-1.2.0-alpha.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-sdk-trace1.2.0opentelemetry-sdk-trace-1.2.0.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-api-metrics1.2.0-alphaopentelemetry-api-metrics-1.2.0-alpha.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-sdk1.2.0opentelemetry-sdk-1.2.0.jar;C:Usersroone.m2repositoryioopentelemetryopentelemetry-semconv1.2.0-alphaopentelemetry-semconv-1.2.0-alpha.jar;C:Usersroone.m2repositoryioousjtoml2.0.0jtoml-2.0.0.jar;C:Usersroone.m2repositorynetbytebuddybyte-buddy1.11.0byte-buddy-1.11.0.jar;C:Usersroone.m2repositoryorgapachecommonscommons-exec1.3commons-exec-1.3.jar;C:Usersroone.m2repositoryorgasynchttpclientasync-http-client2.12.3async-http-client-2.12.3.jar;C:Usersroone.m2repositoryorgasynchttpclientasync-http-client-netty-utils2.12.3async-http-client-netty-utils-2.12.3.jar;C:Usersroone.m2repositoryionettynetty-codec-socks4.1.60.Finalnetty-codec-socks-4.1.60.Final.jar;C:Usersroone.m2repositoryionettynetty-handler-proxy4.1.60.Finalnetty-handler-proxy-4.1.60.Final.jar;C:Usersroone.m2repositoryionettynetty-transport-native-epoll4.1.60.Finalnetty-transport-native-epoll-4.1.60.Final-linux-x86_64.jar;C:Usersroone.m2repositoryionettynetty-transport-native-kqueue4.1.60.Finalnetty-transport-native-kqueue-4.1.60.Final-osx-x86_64.jar;C:Usersroone.m2repositoryorgreactivestreamsreactive-streams1.0.3reactive-streams-1.0.3.jar;C:Usersroone.m2repositorycomtypesafenettynetty-reactive-streams2.0.4netty-reactive-streams-2.0.4.jar;C:Usersroone.m2repositoryorgslf4jslf4j-api1.7.30slf4j-api-1.7.30.jar;C:Usersroone.m2repositorycomsunactivationjakarta.activation1.2.2jakarta.activation-1.2.2.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-safari-driver4.0.0-beta-4selenium-safari-driver-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-support4.0.0-beta-4selenium-support-4.0.0-beta-4.jar;C:Usersroone.m2repositoryorgseleniumhqseleniumselenium-api3.141.59selenium-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的认证。我尝试了不同的方法,但都不起作用。My 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>
任何帮助都将非常感激。由于
我认为这个错误可能与您没有指定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
,我记得这也会导致问题。