使用selenium java 3.11库编译代码时出现“错误:无法访问Killable”

时间:2018-06-08 20:04:06

标签: selenium selenium-webdriver webdriver selenium-firefoxdriver geckodriver

代码编译失败,并显示“错误:无法访问Killable” class FirefoxWebDriver扩展FirefoxDriver { ......

我们已从3.3.1升级到Selenium 3.11。我们正在尝试使用Docker在使用selenium网格配置的浏览器上运行测试。我发现Killable类被删除了。如果我需要更新任何代码chagnes,请建议。

感谢。

1 个答案:

答案 0 :(得分:0)

如果没有项目设置信息(即使用 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 依赖关系的形式,可能是由于存在的一个/多个以下内容:

  • selenium-server 2.21.0.jar
  • 硒 - 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依赖

解决方案

  • 如果您正在使用 Selenium Java Jars 下载并添加相应的jar / jars(来自):

    • 硒 - 服务器 - 独立-3.11.0.jar
    • selenium-java-3.11.0.zip
  • 如果您使用 Malen依赖关系Selenium ,请使用以下任一方法:

    • Selenium Java客户端依赖

      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>3.11.0</version>
      </dependency>   
      
    • Selenium Server依赖

      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-server</artifactId>
          <version>3.11.0</version>
      </dependency> 
      

琐事

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