【问题标题】:Unable to run the script through htmlunit driver in selenium无法通过 selenium 中的 htmlunit 驱动程序运行脚本
【发布时间】:2019-07-13 07:56:01
【问题描述】:

我正在尝试运行 htmlunit 驱动程序,但执行脚本失败

代码:

 public class Testworking 
  {

    public static void main(String args[])throws Exception
     {
        WebDriver driver=new HtmlUnitDriver();
        driver.get("https://www.google.com");
        System.out.println(driver.getTitle());
     }

  }

例外:

  Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException
  at com.online.paypal.test.sampler.Testworking.main(Testworking.java:10)
  Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException
  at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 1 more

我的 pom.xml 文件如下所示:

 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.4.0</version>
 </dependency>
 <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.2</version>
 </dependency>
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.4.0</version>
 </dependency>

是否有人知道我为什么会收到调用目标异常,以及如何解决这个问题。我只想使用 htmlunit 而不是 phanthomjs 或其他无头驱动程序来完成此要求。我只想在不支持任何 chrome 或 firefox 驱动程序的情况下仅使用 htmlunit 启动示例 google.com,并且 VM 没有任何浏览器(Chrome 或 firefox 二进制文件),我只想通过 htmlunit 运行它。

请帮助我实现这一目标。

【问题讨论】:

  • 1.您是否刷新了依赖项? 2.看看这个stackoverflow.com/questions/36698363/…
  • 真的很有帮助
  • @ArrcanaMohan - 只是想知道您使用的 VM 不支持 Chrome/Firefox 浏览器和 phatomjs 吗?
  • 我没有说它不支持我无权访问 ssh 那些机器。它的 GCP 帐户,我们不能直接 ssh 那些。此外,我们无法从全局存储库中获取任何公共图像。这些环境也被码头化了。

标签: java selenium selenium-webdriver htmlunit htmlunit-driver


【解决方案1】:

感谢 beatrice 为您提供的 cmets。我刚刚从 pom.xml 中删除了一些不必要的依赖项,还观察到 htmlunitdriver 默认在 v3.4.0 中可用。我们不需要在 pom.xml 中显式添加它。我进行了全新安装,并更新了 maven 项目 (.m2) 并再次进行了清理和更新。

它解决了问题。

感谢您的所有投入和 cmets。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-11
    • 2014-03-23
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 2011-10-23
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多