无法通过 selenium 中的 htmlunit 驱动程序 运行 脚本

Unable to run the script through htmlunit driver in selenium

我正在尝试 运行 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 或仅使用 htmlunit 的 firefox 驱动程序的情况下启动示例 google.com,并且 VM 没有任何浏览器(Chrome 或 firefox 二进制文件),我只想 运行 通过 htmlunit.

请帮我实现这个目标。

感谢比阿特丽斯的评论。我刚刚从 pom.xml 中删除了一些不必要的依赖项,还观察到 htmlunitdriver 默认情况下在 v3.4.0 中可用。我们不需要在 pom.xml 中明确添加它。我做了全新安装,并更新了 maven 项目 (.m2),再次清理和更新。

它解决了这个问题。

感谢您的所有意见和建议。