2

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.

ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84
  • 1
    1. Have you refreshed your dependencies? 2. Take a look at this https://stackoverflow.com/questions/36698363/java-lang-noclassdeffounderror-org-openqa-selenium-remote-sessionnotfoundexcept – beatrice Feb 19 '19 at 18:37
  • It really helps – ArrchanaMohan Feb 19 '19 at 18:38
  • @ArrchanaMohan - Just want's to know which VM you are using which doesn't supports Chrome/Firefox browsers and phatomjs ? – Amit Jain Feb 19 '19 at 18:53
  • I didnt say it wnt support I dont have access to ssh those machines. Its GCP accounts, We can't ssh those directly. Also, we cant get any public images from global repository. Also those environments are dockerized. – ArrchanaMohan Feb 20 '19 at 06:27

1 Answers1

0

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.

ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84