Selenium Webdriver + Java - Eclipse: Java.Lang.Noclassdeffounderror

Selenium Java 4.1.3 java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

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.

How to solve java.lang.NoClassDefFoundError? Selenium

The error says it all :

java.lang.NoClassDefFoundError: com/google/common/base/Function
at MainTest.openGoogle(MainTest.java:15)

While working with Selenium v3.x you have to download geckodriver.exe from mozilla/geckodriver and place it in your system. Next you have to set the system property through the line System.setProperty() as follows and provide the absolute path of the GeckoDriver binary within your system as follows :

@Before
public void openGoogle()
{
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
wd = new FirefoxDriver();
urll = "https://google.com";
}

Finally Instead of mentioning import org.junit.*; as per best practices mention the distinct exports as follows :

  • import org.junit.Before;
  • import org.junit.Test;
  • import org.junit.After;

Here you can find a detailed discussion on NoClassDefFoundError



Related Topics



Leave a reply



Submit