1

I followed this tutorial https://www.javatpoint.com/selenium-webdriver-installation but I have a problem with the WebDriver class :

Error: Unable to initialize main class First
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

I've put the dependencies as shown in the tutorial. And if I trust the documentation of Selnium API, the WebDriver class is present in the 4.1.3 version.

I don't know if it's because the 4.1.3 version don't have the client-combiden-3.13.0.jar file or something like that... So if you have a solution, I'm in.

I'm on Windows 10, and I use Eclipse IDE version 2021-06 (4.20.0).

And this is my class First :

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

public class First {  
  
    public static void main(String[] args) {

    // declaration and instantiation of objects/variables  
    System.setProperty("webdriver.chrome.driver", "/root/drivers/chromedriver.exe");  
    WebDriver driver = new ChromeDriver();  

    // Launch website
    driver.navigate().to("http://www.google.com/");  

    // Click on the search text box and send value  
    driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");  
 
    // Click on the search button  
    driver.findElement(By.name("btnK")).click();  

    }
}

Thank you for your help!

4
  • Looks like you're missing dependency 'selenium-api' Commented Apr 26, 2022 at 9:02
  • No, I have integrated it and it is 'selenium-api-4.1.3.jar' and also the sources file. I have integrated everything that was in the zip file that I downloaded from the selenium website : selenium.dev/downloads I took the Java zip file in 'Selenium Clients and WebDriver Language Bindings' section. Commented Apr 26, 2022 at 9:34
  • Not sure then but you could try mvn clean, and then mvn compile to see if classes in that jar loads up. Also try to rebuild the project in the IDE. Commented Apr 26, 2022 at 10:49
  • It's a Java project and I can't convert into a Maven project I really don't know why... But thanks for your propositions, I try your idea anyway! Commented Apr 26, 2022 at 13:02

3 Answers 3

1

You probably only added the following JARS:

  • selenium-api-4.1.3.jar
  • selenium-chrome-driver-4.1.3.jar
  • (all in 'lib')

ChromeDriver inherits from ChromiumDriver which again inherits from RemoteWebDriver who finally implements WebDriver. Since you did not provide these links, the compiler cant know that ChromeDriver implements WebDriver.

You at least need to add these external JARS:

  • selenium-api-4.1.3
  • selenium-remote-driver-4.1.3
  • selenium-chromium-driver-4.1.3
  • selenium-chrome-driver-4.1.3
  • (all in the folder 'lib')

Note: you might want to add the xxx-sources.jar too. It is not necessary but you can attach it to the compiled classes to see actual code instead of the weird representation eclipse provides in the "Class File Editor".

You can also add all jar files from the downloaded ZIP to prevent similar errors in the future. Or my preferred way: Look into Maven (https://www.vogella.com/tutorials/EclipseMaven/article.html). It manages dependencies for you, is pretty easy to use and you can update your libraries much easier. You seem to be a new programmer and I know it can look intimidating to get to know all these tools, but Maven will make your life quite a bit easier.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your response, I'm looking into this right know and I'll let you know!
Well, it doesn't work. I can't create a Maven project, I don't know why, I'll look this later. I added the necessary external JAR but I have the same error with this WebDriver class... To add external JAR with Eclipse, I do a right click on my Java Project Properties > Java Build Path > Libraries and in Modulepath, I click on Add External JARs. Am I doing the wrong thing?
That is the problem. Add them to the classpath and it should work.
It seems to work. But know I have some issues with SLF4J and it is added in the dependencies. I found it in the lib folder from the downloaded Selinium zip. I think my main issue has been solved, know I'll search solutions for my SLF4J problem. Thanks a lot!
Glad the main problem is solved for you. Since I am the one to push you direction Maven, I made a minimal Project for eclipse and Maven here: fileconvoy.com/…. To me it helps to look at an existing project to find out where I made my mistake. The ZIP will be available for 21 days - sorry for everyone arriving later.
0

So for those who will have the same issues:

I added all external JARs from the Java Selenium zip file in classpath not in modulepath.

Picture of Java Build Path to add dependencies

After that, I got as error : SLF4J:Failed to load class "org.slf4j.impl.StaticLoggerBinder.

To solve this error, I checked if I had slf4j-api-1.7.36.jar file and I added slf4j-simple-1.7.36.jar. I downloaded it from https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar

And finally, my last issue was the driver I was using, it was not the right version compared to the browser version.

Comments

0

I am also getting this error java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

Then I added all external JARs from the Java Selenium zip file in classpath. Initially I have added to ModulePath.SO that way I got above error.

1 Comment

Just checking. Is this a confirmation that the accepted answer worked for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.