-1

I am started writing script on HtmlUnitDriver but got some error. I am getting error "java.lang.NoClassDefFoundError". Please help me out. Check the code and error in detail below.

Here is the Code:

  package com.pom.sampletests;

        import org.openqa.selenium.By;      
        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.WebElement;  
        import org.openqa.selenium.htmlunit.HtmlUnitDriver;     
        public class HtmlUnitYest {             
            public static void main(String[] args) throws Exception {
                 // Creating a new instance of the HTML unit driver

                 WebDriver driver = new HtmlUnitDriver();

                 Thread.sleep(2000L);
                 // Navigate to Google      
                 driver.get("http://www.google.com");                   

                 // Locate the searchbox using its name     
                 WebElement element = driver.findElement(By.name("q")); 

                 // Enter a search query        
                 element.sendKeys("Guru99");    

                 // Submit the query. Webdriver searches for the form    using the text input element automatically     
                 // No need to locate/find the submit button        
                 element.submit();          

                 // This code will print the page title     
                 System.out.println("Page title is: " +          driver.getTitle());        

                 driver.quit();         
             }      
        }

Here is the error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException
    at com.pom.sampletests.HtmlUnitYest.main(HtmlUnitYest.java:11)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

POM:

  <project xmlns="http://maven.apache.org/POM/4.0.0"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0    http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>TestNGPro</groupId>
  <artifactId>TestNGPro</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>CBA Automation</name> 



            <build>
        <finalName>TestNGPro</finalName>
        <!-- <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> 
            <source>${java.version}</source> <target>${java.version}</target> </configuration> 
            </plugin> -->
        </build>
        <dependencies>
         <dependency>

        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
        </dependency>  

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.10</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-htmlunit-driver -->
        <dependency>
           <groupId>org.seleniumhq.selenium</groupId>
           <artifactId>selenium-htmlunit-driver</artifactId>
           <version>2.52.0</version>
        </dependency>


        </dependencies>

        <properties>
        <java.version>1.6</java.version>
        <selenium.version>3.1.0</selenium.version>
        </properties>
  </project>

Any suggestions might helpful.

sandeep kumar
  • 195
  • 1
  • 4
  • 20

2 Answers2

1

The artifact-id has been changed to htmlunit-driver.

The latest version is now:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>htmlunit-driver</artifactId>
    <version>2.24</version>
</dependency>
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
0

By Degrading the selenium version to 2.53.0 and the problem is solved.

sandeep kumar
  • 195
  • 1
  • 4
  • 20