【问题标题】:Getting error in maven project:FirefoxDriver cannot be resolved to a type在 maven 项目中出现错误:FirefoxDriver 无法解析为类型
【发布时间】:2013-06-27 01:19:27
【问题描述】:

我已经在 pom.xml 中添加了 selenium 项目所需的所有依赖项。但是当我尝试使用以下命令启动 Firefox 驱动程序时仍然出现错误:WebDriver driver = new FirefoxDriver();
我的 pom.xml :

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.ans</groupId>
<artifactId>motion</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>motion</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <properties>
                    <property>
                        <name>usedefaultlisteners</name>
                        <value>false</value>
                    </property>
                    <property>
                        <name>listener</name>
                        <value>org.uncommons.reportng.HTMLReporter,
                            org.uncommons.reportng.JUnitXMLReporter</value>
                    </property>
                </properties>
                <workingDirectory>target/</workingDirectory>
            </configuration>
        </plugin>

    </plugins>
</build>
<repositories>
    <repository>
        <id>java-net</id>
        <url>http://download.java.net/maven/2</url>
    </repository>

</repositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>0.8.1</version>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path-assert</artifactId>
            <version>0.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.28.0</version>
        </dependency>
        <dependency>
            <groupId>com.opera</groupId>
            <artifactId>operadriver</artifactId>
            <version>1.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-remote-driver</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.webdriver</groupId>
            <artifactId>webdriver-firefox</artifactId>
            <version>1.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

【问题讨论】:

    标签: java maven


    【解决方案1】:

    确保您已在代码中导入了 FirefoxDriver 类。在您的导入部分添加以下行。

    import org.openqa.selenium.firefox.FirefoxDriver;
    

    【讨论】:

    • 谢谢 karthikeyan。我在 .m2 文件夹中的一个 jar 已损坏。我从 m2 文件夹中删除了该 jar 并进行了 mvn clean install。这解决了我的问题..:)
    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    • 2013-09-02
    • 2023-03-23
    相关资源
    最近更新 更多