这是我正在使用的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>shiv</groupId>
<artifactId>xyz</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>ab</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <webdriver.version>2.53.0</webdriver.version>
    <junit.version>4.12</junit.version>
    <hamcrest.version>1.3</hamcrest.version>
    <ghostdriver.version>1.1.0</ghostdriver.version>
    <phantomjs-maven-plugin.version>0.7</phantomjs-maven-plugin.version>
    <phantomjs.version>2.1.1</phantomjs.version>

</properties>


<dependencies>

    <!-- Junit 4.11 needs hamcrest 1.3 -->
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>${hamcrest.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>${webdriver.version}</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>2.53.0</version>
        <scope>test</scope>
        </dependency>


如您所见,我已经获得了最新的硒版本2.5.3,但仍然发出以下错误:

[错误]编译错误:

[错误] /Users/sp/xyz/src/main/java/webdriver/manager/Driver.java:[6,1]包org.openqa.selenium不存在

[错误] /Users/sp/xyz/src/main/java/webdriver/manager/Driver.java:[11,36]包org.openqa.selenium.html单元不存在

有什么我想念的吗?

最佳答案

我在您的pom.xml中看不到htmlunit-driver依赖性。从2.53.0开始,您需要显式包含HtmlUnitDriver作为要包含它的依赖项。

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>htmlunit-driver</artifactId>
        <version>2.21</version>
</dependency>


有关更多详细信息,请参见this

10-04 22:17
查看更多