gpt4 book ai didi

java - 设置 htmlunit 的类路径

转载 作者:行者123 更新时间:2023-11-30 04:58:05 24 4
gpt4 key购买 nike

我正在尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com