0

I installed JDK from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html (This version for windows x64: Java SE Development Kit 8u151)

I downloaded eclipse from here: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/oxygenr (Windows 64-bit)

I opened a new project in eclipse: File->New->Java Project

Then I downloaded Selenium Java Jars from here: http://www.seleniumhq.org/download/ ---> java language

Then in eclipse I click on my project -> properties ->Java Build Path -> Libraries tab -> Add External JARs... -> I go to "SeleniumDrivers\Java" library (there I saved all the JARS that I downloaded) -> I checked all the files there: these files

I clicked on "ok" and created a new class in eclipse

Then I downloaded chromedriver from here: http://www.seleniumhq.org/download

I unzipped it and saved it here: C:\Selenium\Drivers

This is my script:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class MainClass {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("hi there\n");

        System.setProperty("webdriver.chrome.driver", 
        "C:/Selenium/Drivers/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.facebook.com");
    }

}

As you can see, this is a very basic script which opens chrome browser and navigate to facebook.

I run this script and got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/config/RegistryBuilder
    at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:69)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:242)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:219)
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
    at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at MainClass.main(MainClass.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.RegistryBuilder
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 13 more

I don't know how to resolve this issue, can you please help to solve it so that I will be able to run my basic script?

John Pj
  • 43
  • 1
  • 1
  • 11
  • 1
    Have you considered using a build system like Gradle? That would allow you to not have to manually manage your dependencies. It looks to me like the jars you acquired, or specifically the jars you added to your project doesn't include the library that the `RegistryBuilder` class is in. That class appears to be in the Apache HttpCore jar, so I'd consider looking around to ensure you're including it, and even go download it if necessary to see if it affects your results. – Julian Nov 03 '17 at 20:50
  • Hi thanks, I included it so this is not the problem I guess – John Pj Nov 03 '17 at 21:00
  • Was it provided as part of the webdriver jar bundle you downloaded? Or did you download it as a separate entity to include? If you downloaded it separately, Try making sure that it is a version that is compatible with the version of webdriver you're using. Regardless of why, whichever jar is expected to have that class definition is your problem, and your fix is very likely going to have some level of something to do with it – Julian Nov 03 '17 at 21:42
  • Possible duplicate of [NoClassDefFoundError: org/apache/http/HttpEntity in Selenium for ChromeDriver?](https://stackoverflow.com/questions/23471340/noclassdeffounderror-org-apache-http-httpentity-in-selenium-for-chromedriver) – JeffC Nov 04 '17 at 00:25

7 Answers7

2

java.lang.NoClassDefFoundError is observed when the JRE can't find a Class.

In simple words the required imports or jar files are not available. From the snapshot you have shared its pretty much evident that you have tried to add the Java Client related jars.

In this case you need to follow the following steps:

  1. Remove all the jars referring to previous versions of Selenium standalone server & Selenium Java client
  2. Import only the selenium-server-standalone-3.7.0.
  3. In your IDE within Project menu, select the option Build Automatically and execute the Clean option for all of your Projects.
  4. Execute your Test.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

Seems like the latest (v3.7) Selenium-Java zip file contains lesser jars in the lib folder. v3.6 contained 10 lib jars but v3.7 contains only 7 jars.

The missing jar which is causing all the issue for the op is 'httpcore-4.4.6.jar'. I am not sure whether the removal of jar is intentional or not. Maybe chromedriver has catch up with Selenium java 3.7seeing that .

I the mean time use Selenium Java 3.6. Don't forget to add the /lib folder as well.

http://selenium-release.storage.googleapis.com/3.6/selenium-java-3.6.0.zip

StrikerVillain
  • 3,719
  • 2
  • 24
  • 41
0

i've added the three missing jars from version 3.6 and fixed everything. http://selenium-release.storage.googleapis.com/3.6/selenium-java-3.6.0.zip

0

update the the appium java-client to 7.3.0 and selenium-java to 3.141.59 this resolved my issue hope it helps.

0

I faced the same issue. For me, it didn't found the WebDriver. It seemed to happen as I imported the libraries the location other than classpath. Then I opened up a new project, went to the Properties>Java Build Path>Libraries. This time I imported the libraries under classpath. Now it works fine.

0

For those who are using Appium java client with Selenium, don't try to import Java client and selenium dependencies together in your pom.xml, you have already selenium dependencies imported with the java client dependency, you only have to import Java client dependency in your pom.xml and it should work. Reference: https://mvnrepository.com/artifact/io.appium/java-client/7.6.0

0

For me, the issue was solved by adding the external jars (selenium-java jar files) to 'Classpath', instead of to 'Modulepath'

enter image description here

Ronwald
  • 13
  • 4