Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.ClassNotFoundException:WebDriver API_Java_Selenium_Webdriver - Fatal编程技术网

java.lang.ClassNotFoundException:WebDriver API

java.lang.ClassNotFoundException:WebDriver API,java,selenium,webdriver,Java,Selenium,Webdriver,我下载了selenium-java-2.0a5.zip 并运行以下代码: package org.openqa.selenium.example; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.htmlunit.HtmlUnitDriver; public class

我下载了selenium-java-2.0a5.zip

并运行以下代码:

package org.openqa.selenium.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class Example  {
    public static void main(String[] args) {
        // Create a new instance of the html unit driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new HtmlUnitDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("Cheese!");

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
    }
}
但后来我

    at org.openqa.selenium.example.Example.main(Example.java:13)
Caused by: java.lang.ClassNotFoundException: com.gargoylesoftware.htmlunit.WebWindowListener
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more
我漏了一步吗?我确保将selenium-java-2.0a5.jar导入到项目中。

您似乎在项目中使用了“HtmlUnit”,而其jar在类路径中丢失。
添加selenium时将其添加到项目属性中。

htmlunit jar不在类路径中。还包括selenium-java-2.0a5.jar的依赖项库jar。我确信它们一定是在您下载的zip中提供的,您想从中下载selenium-server-standalone-2.0a5.jar,因为这包括依赖项。

检查我的答案。您忘记将HtmlUnit的jar添加到类路径。