java - Selenium 程序抛出编译错误 org.openqa.selenium.internal.Killable cannot be resolved

标签 java maven selenium selenium-webdriver

我使用 Selenium 和 Maven 创建了一个新的 Java 项目。这是pom.xml中的相关内容

<dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.45.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.8.1</version>
    </dependency>

</dependencies>

然后我创建了这个使用 Selenium 框架的基本 Java 程序:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Start {
    public static void main(String[] args) {
        // declaration and instantiation of objects/variables
        System.setProperty("webdriver.firefox.marionette", "D:\\geckodriver.exe");

        WebDriver driver = null;
        try {
            driver = new FirefoxDriver();
            String baseUrl = "https://www.google.co.in/";

            driver.get(baseUrl);

        } finally {
            driver.close();
        }

    }
}

但是,我遇到了这个编译错误:

The type org.openqa.selenium.internal.Killable cannot be resolved. It is indirectly referenced from required .class files

有人可以建议我哪里出错了吗?

最佳答案

pom.xml 中删除此依赖项:

   <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.8.1</version>
    </dependency>

您使用的是 Selenium java 绑定(bind)的 vesrion 2.45.0(2015 年 2 月发布):

  <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.45.0</version>
    </dependency>

如果您检查上述包的编译依赖项:https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/2.45.0
你会看到这个包依赖于 selenium-chrome-driver 2.45.0 包。 Maven会在编译时自动解决这个依赖,所以你不需要在pom.xml中声明这个包。文件。


但是,如果您直接在 pom.xml 文件中将此包 selenium-chrome-driver 声明为依赖项,使用不同的版本(最新的 3.8. 1),那么maven在编译时会使用这个版本3.8.1而不是2.45.0,这会导致错误- wrong, incompatibile jar使用库。

关于java - Selenium 程序抛出编译错误 org.openqa.selenium.internal.Killable cannot be resolved,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47616255/

相关文章:

Java 条件语句/初始化变量

java - 我可以在使用 Spring AOP 的方法中拦截空指针异常吗?

java - 在 Java 中计算 ConcurrentHashmap 中的 delta

java - Selenium FirefoxDriver 如何使用 Crontab 执行自动化测试

java - 如何通过Selenium和Page Factory实现AjaxElementLocatorFactory?

java - Android 保存和加载字符串和 boolean 值的 1D 和 2D 数组

Eclipse 3.7/Indigo m2e WTP 集成依赖问题

java - 由于依赖项和/或插件而导致 pom.xml 文件错误

java - 如何替换 SLF4J 中的 MarkerIgnoringBase

selenium - 如何更改 selenium/hub docker 容器的端口?