如果没有您的项目设置信息(即您正在使用Selenium JAR、Ant、Maven),很难分析/得出结论 或 Gradle),您的代码试验和错误堆栈跟踪。
但是这个错误信息...
error: cannot access Killable
...表示您的程序在访问 Killable 时遇到错误。
Killable.class 文件
根据Killable ClassNotFound 的讨论,Killable.class 文件包含在selenium-api-2.21.0.jar 中。此外,使用 selenium-server 2.21.0 的 Maven 依赖项 会产生错误:
Exception in thread "main" java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Killable
说明
正如您所提到的,您已从 Selenium 3.3.1 升级到 Selenium 3.11,可能的原因是您所使用的二进制文件之间存在版本冲突以 JARs、Maven 或 Gradle 依赖的形式使用,并且可能是由于 存在 的一个/多个其中:
- 硒服务器 2.21.0.jar
- selenium-api-2.21.0.jar
-
selenium-server 2.21.0 或 selenium-api-2.21.0 的 Maven 依赖项
-
selenium-server 2.21.0 或 selenium-api-2.21.0 的 Gradle 依赖项
解决方案
琐事
如果您使用的是 Maven,您可以在您的 root pom 中添加此块(在构建部分中,只需添加到插件中)来解决您使用的不同版本的二进制文件得到了。
<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<DependencyConvergence />
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
供您参考selenium-server 2.21.0输出树如下:
[INFO] \- org.seleniumhq.selenium:selenium-server:jar:2.21.0:compile
[INFO] +- org.bouncycastle:bcprov-jdk15on:jar:1.47:compile
[INFO] +- mx4j:mx4j-tools:jar:3.0.1:compile
[INFO] +- org.mortbay.jetty:servlet-api-2.5:jar:6.1.9:compile
[INFO] +- org.seleniumhq.selenium:jetty-repacked:jar:7.6.1:compile
[INFO] +- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] +- org.seleniumhq.selenium:selenium-java:jar:2.21.0:compile
[INFO] | +- org.seleniumhq.selenium:selenium-android-driver:jar:2.21.0:compile
[INFO] | | \- org.seleniumhq.selenium:selenium-remote-driver:jar:2.21.0:compile
[INFO] | | +- cglib:cglib-nodep:jar:2.1_3:compile
[INFO] | | +- org.json:json:jar:20080701:compile
[INFO] | | \- com.google.guava:guava:jar:11.0.1:compile
[INFO] | | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | +- org.seleniumhq.selenium:selenium-chrome-driver:jar:2.21.0:compile
[INFO] | +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.21.0:compile
[INFO] | | +- org.seleniumhq.selenium:selenium-api:jar:2.21.0:compile
[INFO] | | +- net.sourceforge.htmlunit:htmlunit:jar:2.9:compile
[INFO] | | | +- xalan:xalan:jar:2.7.1:compile
[INFO] | | | | \- xalan:serializer:jar:2.7.1:compile
[INFO] | | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | | | +- org.apache.httpcomponents:httpmime:jar:4.1.2:compile
[INFO] | | | +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.9:compile
[INFO] | | | +- xerces:xercesImpl:jar:2.9.1:compile
[INFO] | | | | \- xml-apis:xml-apis:jar:1.3.04:compile
[INFO] | | | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.15:compile
[INFO] | | | +- net.sourceforge.cssparser:cssparser:jar:0.9.5:compile
[INFO] | | | | \- org.w3c.css:sac:jar:1.3:compile
[INFO] | | | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | | \- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
[INFO] | +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.21.0:compile
[INFO] | | +- commons-io:commons-io:jar:2.0.1:compile
[INFO] | | \- org.apache.commons:commons-exec:jar:1.1:compile
[INFO] | +- org.seleniumhq.selenium:selenium-ie-driver:jar:2.21.0:compile
[INFO] | | +- net.java.dev.jna:jna:jar:3.4.0:compile
[INFO] | | \- net.java.dev.jna:platform:jar:3.4.0:compile
[INFO] | +- org.seleniumhq.selenium:selenium-iphone-driver:jar:2.21.0:compile
[INFO] | +- org.seleniumhq.selenium:selenium-safari-driver:jar:2.21.0:compile
[INFO] | +- org.seleniumhq.selenium:selenium-support:jar:2.21.0:compile
[INFO] | \- org.webbitserver:webbit:jar:0.4.6:compile
[INFO] | \- org.jboss.netty:netty:jar:3.2.7.Final:compile
[INFO] +- org.yaml:snakeyaml:jar:1.8:compile
[INFO] \- commons-codec:commons-codec:jar:1.6:compile