本文介绍了java.lang.ClassNotFoundException:WebDriver API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下载了selenium-java-2.0a5.zip
I downloaded the 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 导入到项目中。
Did I miss a step ? I made sure to import the selenium-java-2.0a5.jar into the project.
推荐答案
htmlunit jar不在类路径中。包括selenium-java-2.0a5.jar的依赖lib jar。我相信它们必须以您下载的邮政编码提供
htmlunit jar is not in the classpath. Include dependency lib jars of selenium-java-2.0a5.jar as well. I am sure they must have been provided in the zip you downloaded
这篇关于java.lang.ClassNotFoundException:WebDriver API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!