java - 设置 htmlunit 的类路径

标签 java unix classpath selenium-webdriver 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 库弄乱了......

最佳答案

您还应该在运行测试时指定类路径,而不仅仅是在编译期间。

(此外,IIRC 独立 jar 已包含 htmlunit;您可能不需要显式包含 htmlunit jar。)

关于java - 设置 htmlunit 的类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7871673/

相关文章:

java - 如何在进度条处于 Activity 状态之前禁用控件

c - 除非在使用输出重定向时调用显式 fflush 函数,否则线程不会给出输出

java - 又是字符串转换: UNIX Windows-1252 to String

c++ - 当两者都是变量时如何将 float 除以整数?

java - Mahout - 尝试维基百科示例时出错

java - eclipse从哪个目录启动jvm?

scala - IntelliJ IDEA/Scala - 无法读取资源

java - 让 JButton 关闭窗口,但在关闭之前在 WindowClosing(WindowEvent e) 中运行代码

java - 当一个线程完成后,如何通知主线程?

java - NoClassDefException,从另一个包开始 Activity