我使用 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/