如何解决htmlUnit WrapsDriver错误



我正在用带有selenium 3.13 jar的HtmlUnit运行测试,浏览器成功启动,但之后它停止工作,出现以下错误。

> Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WrapsDriver
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.toWebElement(HtmlUnitDriver.java:1211)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:1341)
at org.openqa.selenium.By$ByName.findElement(By.java:284)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2024)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2020)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1660)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:2020)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:798)
at com.directlegalmail.startup.Startup.scrapDates(Startup.java:89)
at com.directlegalmail.startup.Startup.main(Startup.java:63)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WrapsDriver
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)
... 22 more

有人知道怎么解决吗,我知道硒3.13和htmlUnit驱动程序2.33

下面是我的代码

driver = new HtmlUnitDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait
(10000,TimeUnit.MILLISECONDS);
logMsg("Browser launched successfully");
driver.get("WebURL");

如果需要使用具有依赖关系的htmlUnit-Driver-x.xx.x-jar-with-dependences.jar,请从github下载最新的htmlUnit-Driver-x.xx.x-jar-with-dependences.html,其中包含WrapsDriver类。

有关测试环境的更多信息会让我们更了解到底出了什么问题。

但是,我在您的代码块中没有看到任何重大问题。使用Selenium v3.14HtmlunitDriver v2.33.0,在调用HtmlunitDriver时,您需要传递参数true以启用JavaScript,您可以使用以下解决方案:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class A_HtmlunitDriver_2_33_0 {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new HtmlUnitDriver(true);
driver.manage().window().maximize();
driver.get("https://stackoverflow.com/questions/53812207/how-to-resolve-htmlunit-wrapsdriver-error");
System.out.println("HtmlUnitDriver invoked");
driver.quit();
}
}

这种依赖关系的组合对我有效:

implementation("org.seleniumhq.selenium:selenium-java:3.141.59")
implementation("org.seleniumhq.selenium:selenium-api:3.141.59")
implementation("org.seleniumhq.selenium:htmlunit-driver:2.36.0")

您可以在此处查看HtmlUnit驱动程序版本2.36.0的兼容Selenium依赖项:https://github.com/SeleniumHQ/htmlunit-driver/blob/2.36.0/pom.xml

相关内容

  • 没有找到相关文章

最新更新