Home > Enterprise >  Unable to find ChromeDriver class with Selenium
Unable to find ChromeDriver class with Selenium

Time:07-06

I have my chromedriver executable file in my MacOS Downloads directory. Here's my code when I'm setting up for using Selenium

    import java.lang.*;
    import java.io.*;
    import java.util.*;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    
    public class Scraper {
        public static void main(String[] args) {
           beforeTest();
            }
         public static void beforeTest() {
            System.setProperty("webdriver.chrome.driver", "/Users/ngan.nguyen/Downloads/chromedriver.exe");
            WebDriver driver = new ChromeDriver();
            driver.navigate().to("https://www.indeed.com/");
            driver.manage().window().maximize();
        }
    }

And I got this exception: cannot found the ChromeDriver class

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/http/HttpClient$Factory
    at Scraper.beforeTest(Scraper.java:39)
    at Scraper.main(Scraper.java:32)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.http.HttpClient$Factory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 2 more

I think it was because my path to chromedriver is not correct in the setProperty method. Chromedriver and Chrome versions are compatible. I also downloaded all needed jar files. How do I get the correct path or is it because of something else? (I'm using IntelliJ)

CodePudding user response:

  • Path of the chrome driver exe should be full from drive name.

  • You can keep driver exe in project folder and use it by giving path as "./FolderName/chromeDriver.exe");

       System.setProperty("webdriver.chrome.driver, "C//chromedriver.exe);
    

CodePudding user response:

THIS IS A BAD PRACTICE TO SPECIFY PATH.

Always put your drivers in your work directory and then use "system.getProperty" to locate the driver.

String src = System.getProperty("user.dir")   "/bin/geckodriver.exe";
System.setProperty("webdriver.gecko.driver", src);

enter image description here

  • Related