【问题标题】:Cannot find selenium package even if it is defined in pom.xml file即使在 pom.xml 文件中定义了 selenium 包也找不到
【发布时间】:2016-06-13 17:49:19
【问题描述】:

这是我正在使用的 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,但它仍然给出以下错误:

[错误] 编译错误:

[错误] /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.htmlunit 不存在

我有什么遗漏的吗?

【问题讨论】:

    标签: java maven selenium


    【解决方案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

    【讨论】:

    • 所以,我添加了上述更改并且它有效,但仍然抱怨包“org.openqa.selenium”不存在。
    • 尝试使用 org.seleniumhq.seleniumselenium-java2.53.0
    • 好的,找到问题了..由于某种原因它没有添加到我的课程路径中..感谢您的帮助..感谢它..
    猜你喜欢
    • 2016-09-20
    • 2019-05-10
    • 1970-01-01
    • 2018-01-19
    • 2016-02-09
    • 1970-01-01
    • 2015-07-25
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多