即使在pom.xml文件中定义了selenium包也找不到

时间:2016-06-13 17:49:20

标签: java maven selenium

这是我正在使用的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>

正如您所看到的,我已经获得了最新的selenium 2.5.3版本,但仍然会出现以下错误:

[错误]编译错误:

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

[ERROR] /Users/sp/xyz/src/main/java/webdriver/manager/Driver.java:[11,36]包org.openqa.selenium.htmlunit不存在

有没有我错过的东西?

1 个答案:

答案 0 :(得分:1)

我没有在你的pom.xml中看到 htmlunit-driver 依赖关系。从 2.53.0 开始,您需要明确包含HtmlUnitDriver作为依赖项以包含它。

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

有关详细信息,请参阅this