package webdriverbasic;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Webdriverbasicclass {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Sammy\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/chrome/ChromeDriver
at webdriver/webdriverbasic.Webdriverbasicclass.main(Webdriverbasicclass.java:10)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.chrome.ChromeDriver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
exception in thread main java lang noclassdeffounderror
its my first program in eclipse with selenium and i got this error and not able to invoke the browser
CodePudding user response:
It looks like a problem with the selenium jar. You havent referenced it properly. The best option is to create gradle/maven project and add the selenium as depedency. Here is an example how to add it in maven pom file:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.6.0</version>
</dependency>
</dependencies>
The path to webdriver looks OK.
CodePudding user response:
First way: You should download selenium jar files then add it to your project. Right click on your project > build path > configure build path Select java build path > libraries > add external Jars. browse where you add selenium jars then select it.
Second: You can create a maven project which is a management tool you can install its plugin from eclipse marketplace. open pom.xml file in the project then under dependencies, add the following code:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.6.0</version>
</dependency>