当我尝试从示例加载此代码时存在依赖性问题。可能唯一的区别是我使用Maven来加载依赖项。我已经包含了所需的测试库并下载了chromedriver.exe
。
还有什么可以遗漏?
以下依赖性错误由ChromeDriverService.Builder()
:
The type org.openqa.selenium.remote.service.DriverService$Builder cannot be resolved. It is indirectly referenced from required .class files
这里加载了类ChromeDriverService.Builder()
:
@BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("chromedriver.exe"))
.usingAnyFreePort()
.build();
service.start();
}
以下是我测试的Maven依赖项:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.2</version>
</dependency>
答案 0 :(得分:1)
您需要添加org.seleniumhq.selenium:selenium-chrome-driver
作为依赖项(我还建议您使所有org.seleniumhq.selenium
个依赖项使用相同的版本):
e.g。
<properties>
<selenium.version>2.48.2</selenium.version>
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>