0
import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.chrome.ChromeDriver;  
  
public class Frst{  
  
    public static void main(String[] args) {  
        
    // declaration and instantiation of objects/variables  
    System.setProperty("webdriver.chrome.driver", "F:\\Eclipse\\New folder\\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("hudai");  
          
    // Click on the search button  
    driver.findElement(By.name("btnK")).click();  
      
    }  
  
}

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

Raihan Rahman
  • 1
  • 1
  • 1
  • 1
  • Does this answer your question? [Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver](https://stackoverflow.com/questions/47823506/exception-in-thread-main-java-lang-noclassdeffounderror-org-openqa-selenium-w) – seenukarthi Apr 21 '22 at 07:26

1 Answers1

1

You must add external jar files to classpath instead of module path. Steps.

  1. Right-click on the project and navigate to properties.
  2. Go to the Java Build path, it's in the left section
  3. Then go to the libraries section. remove all the jar files from modulatpath.
  4. to remove all jar files, select the jar file and click on the remove button on the right side.
  5. After that select classpath and click on add external jar and import all the jar files including lib folder.
  6. Click on apply and close.

You will then be able to run the test script.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83