javaseleniumselenium-webdriverhtmlunithtmlunit-driver

Unable to run the script through htmlunit driver in selenium


I'm trying to run the htmlunit driver but It's failed to execute the script

Code:

 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:

  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

And my pom.xml file looks like below:

 <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>

Is anybody have idea why I'm getting invocation target exception, and how can I over come this issue. I just want to done this requirement only using htmlunit not with phanthomjs or other headless driver. I just want to launch the sample google.com without support of any chrome or firefox driver only using htmlunit and the VM didnt have any browser (Chrome or firefox binaries) and I just want to run it through htmlunit.

Please help me to achieve this.


Solution

  • Thanks to beatrice for yours comments. I just removed some unnecessary dependencies from pom.xml also observed that htmlunitdriver is available in v3.4.0 by default. We no need to add that explicitly in pom.xml. I did clean install, and updated the maven project (.m2) cleaned and updated again.

    It resolved the issue.

    Thanks for all your inputs and comments.