0
package exsc;

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

public class S1 {

   public static void main(String[] args) {
          // TODO Auto-generated method stub
          // Give me the count of Links on a page  

          System.setProperty("webdriver.chrome.driver","C:\\JARs\\chromedriver_win32\\chromedriver.exe");
      WebDriver driver = (WebDriver) new ChromeDriver();
      String url= "http://qaclickacademy.com/practice.php";
      driver.get(url);
      System.out.println(driver.findElements(By.xpath("a")).size());
   }
}

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/chrome/ChromeDriver at exsc.S1.main(S1.java:13) Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.chrome.ChromeDriver at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 1 more

2
  • WebDriver driver = (WebDriver) new ChromeDriver(); - why are you casting your driver object here? WebDriver driver = new ChromeDriver(); should work fine.
    – Brian
    Sep 9, 2019 at 21:23
  • 1
    Earlier it forced me to cast in order to compile successfully. Now the issue is resolved.
    – Mani
    Sep 9, 2019 at 21:39

2 Answers 2

1

Just a minor point, instead of using xpath it'll be good if you use tagName in this scenario to find all the links. Something like this:

driver.findElements(By.tagName("a")).size();
1

Issue found with JAR mappings to the current project. Instead of importing external JARs to classpath in Build Path, it got imported to Modulepath.

Rearranging JARs solved the issue.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.