Selenium Webdriver + Java - Eclipse: java.lang.NoClassDefFoundError

0 votes

I have installed java and eclipse, and downloaded the JARS and placed them in the right directory as it should be. Below is my script:

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

public class myClass {

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

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

And i get the below 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 myClass.main(myClass.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

This is my first script and i'm getting an error even though its basic. Can someone plz help?

Apr 13, 2018 in Selenium by kappa3010
• 2,020 points
10,634 views

I also found found the same issue. 

My code is :

package abcd;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Admin {

public static void main(String[] args) throws InterruptedException {

//Instantiate Chrome Browser Driver

System.setProperty("webdriver.chrome.driver","C://Users//Falgu//AutomationProfile//chromedriver.exe");

//Create Chrome Browser Driver

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get("https://www.google.com");

//driver.quit();

}

}

And got below error 

Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809@{#864}) on port 27898

Only local connections are allowed.

Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 76

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'

Driver info: driver.version: ChromeDriver

remote stacktrace: Backtrace:

Ordinal0 [0x009D7C93+1473683]

Ordinal0 [0x0095ADB1+961969]

Ordinal0 [0x008E42E3+475875]

Ordinal0 [0x0087F365+62309]

Ordinal0 [0x0087BC77+48247]

Ordinal0 [0x00899149+168265]

Ordinal0 [0x00898D1D+167197]

Ordinal0 [0x0089742B+160811]

Ordinal0 [0x00880AE6+68326]

Ordinal0 [0x00881BF0+72688]

Ordinal0 [0x00881B89+72585]

Ordinal0 [0x00974B77+1067895]

GetHandleVerifier [0x00A76875+506677]

GetHandleVerifier [0x00A76610+506064]

GetHandleVerifier [0x00A7D1B8+533624]

GetHandleVerifier [0x00A7704A+508682]

Ordinal0 [0x0096C266+1032806]

Ordinal0 [0x0096C0DF+1032415]

Ordinal0 [0x00976A8B+1075851]

Ordinal0 [0x00976BF3+1076211]

Ordinal0 [0x00975BA5+1072037]

BaseThreadInitThunk [0x74C433CA+18]

RtlInitializeExceptionChain [0x77449ED2+99]

RtlInitializeExceptionChain [0x77449EA5+54]

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)

at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)

at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)

at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)

at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)

at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)

at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)

at java.util.stream.AbstractPipeline.copyInto(Unknown Source)

at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)

at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)

at java.util.stream.AbstractPipeline.evaluate(Unknown Source)

at java.util.stream.ReferencePipeline.findFirst(Unknown Source)

at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)

at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)

at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)

at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)

at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)

at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)

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 abcd.Admin.main(Admin.java:12)

- I have added Jar files as well. and followed the steps which mentioned by king_kenny . But still facing the issue.

Please someone help me.

Hey there, you can first check which version of ChromeDriver is supported by Chrome Browser. You can simple google which version of ChromeDriver is supported by Chrome Browser version-76.

Then you can delete previously installed ChromeDriver.exe file and install the supported version.
Thank you so much. it is working. :)
Good to hear that. You can also post any other queries you have, here on Community.

3 answers to this question.

0 votes

java.lang.NoClassDefFoundError is usually thrown when the installed JRE cannot find the Class which needs to be executed.

Also, the required imports and JARS would also not be available. It seems like you have tried to add the jars related to Java Client. So the only solution is to remove and place all the JARS again correctly.
Do th following:

  1. Remove all JARS including Selenium standalone server & Selenium Java client
  2. Import all the JARS which you downloaded from here: https://www.seleniumhq.org/download/.
  3. Make sure to import them to "Add External JARS" from "Conigure Build Path" option in Eclipse IDE.

This has to definately work.

answered Apr 13, 2018 by king_kenny
• 3,650 points
0 votes
can you the path like this way - C:\\Users\\Desktop\\SELENIUM\\chromedriver.exe
answered Feb 23 by anonymous
Yes, that's correct by the help of escaping character the error can be solved.
+2 votes
I also faced this issue first time, in order to solve this I checked build path configured for my project.There you will see two options 1. Module path 2. Class path

Add your all external jars such as selenium jars under class path not module path and retry. It worked for me.
answered Aug 28 by Shraddha
Hi Shraddha, thank you for sharing your solution.
It helped. Thankyou
You're welcome. You can also post your issues/queries on this community.
Thanks a bunch, It worked like charm for me too.

Thanks again
Glad it worked for you!!!
Thank u so much.It helped me alot
Thanks a ton.

I have been searching for this for a couple of hours!

Thanks a lot...i was struggling with this issue. it worked for me. Thanks again.

You're welcome nyan. You can post any other questions if you have on Selenium.

Related Questions In Selenium

0 votes
1 answer

Java.lang.CharSequence cannot be resolved error while using sendKeys() using Selenium Webdriver

You could try this, myElement .sendKeys(new String[] { ...READ MORE

answered Apr 4, 2018 in Selenium by Johnathon
• 9,080 points
745 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,110 points
2,279 views
+1 vote
3 answers

java.lang.ClassNotFoundException: okhttp3.ConnectionPool - Selenium Error

The only reason for ClassNotFoundException is if ...READ MORE

answered Mar 30, 2018 in Selenium by nsv999
• 5,110 points
3,160 views
0 votes
1 answer

How to perform mouse hovering in Selenium WebDriver (Java)?

You many not actually be able to ...READ MORE

answered Apr 3, 2018 in Selenium by nsv999
• 5,110 points

edited Apr 4, 2018 by nsv999 3,302 views
0 votes
1 answer
0 votes
1 answer

How to scroll the Page up or down in Selenium WebDriver? (using java)

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,110 points
8,384 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
938 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,119 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
859 views