有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

maven项目中的java获取错误:FirefoxDriver无法解析为类型

我已经在pom中添加了所有依赖项。selenium项目需要xml。但当我尝试使用:WebDriver driver=newfirefoxdriver()启动firefox驱动程序时,仍然会出现错误
我的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>


共 (1) 个答案

  1. # 1 楼答案

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

    import org.openqa.selenium.firefox.FirefoxDriver;