设置 htmlunit 的类路径
我正在尝试使用 selenium 浏览器自动化框架编写一个简单的程序,并且我需要使用 htmlunit 库。
这是我的代码:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Test {
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.google.com");
System.out.println(driver.getTitle());
}
}
所以它应该打印出“Google”,但我不断收到: “java.lang.ClassNotFoundException:org.openqa.selenium.htmlunit.HtmlUnitDriver”
我在unix终端中运行它,所以这就是我输入运行它
export CLASSPATH=selenium-2.9.0/selenium-server-standalone-2.9.0.jar:selenium-2.9.0/libs/htmlunit-2.9.jar
javac -cp $CLASSPATH Test.java
java Test
然后我得到错误......所以任何建议?我似乎加载了这两个库,但我知道我把 htmlunit 库弄乱了......
I'm trying to code a simple program using the selenium browser automation framework and I need to use the library htmlunit.
Se here's my code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Test {
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.google.com");
System.out.println(driver.getTitle());
}
}
So it should print out "Google" but I keep getting:
"java.lang.ClassNotFoundException: org.openqa.selenium.htmlunit.HtmlUnitDriver"
I'm running this in unix terminal, so this is what I'm typing in to run it
export CLASSPATH=selenium-2.9.0/selenium-server-standalone-2.9.0.jar:selenium-2.9.0/libs/htmlunit-2.9.jar
javac -cp $CLASSPATH Test.java
java Test
And then I get the error... So any suggestions? I seem to load both libraries, but I know that I'm messing something up with the htmlunit library...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还应该在运行测试时指定类路径,而不仅仅是在编译期间。
(此外,IIRC 独立 jar 已包含 htmlunit;您可能不需要显式包含 htmlunit jar。)
You should specify the classpath when you run the test, too, not just during compilation.
(Also, IIRC the standalone jar contains htmlunit already; you might not need to explicitly include the htmlunit jar.)