0

I little help here will be appreciated.I am simply trying to open a site using selenium and here is the code. Getting java.lang.IllegalStateException error.

   package pkg1;

   import org.openqa.selenium.WebDriver;
   import org.openqa.selenium.chrome.ChromeDriver;
   //import org.openqa.selenium.firefox.FirefoxDriver;


   public class training1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
   System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
        System.out.println("Welcome to Selenium");
        driver.get("https://in.yahoo.com/");

    }

}

----- Error -----
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
    at pkg1.training1.main(training1.java:14)

1 Answer 1

1

You must set path of the chromedriver.exe before calling new ChromeDriver()

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    System.out.println("Welcome to Selenium");
    driver.get("https://in.yahoo.com/");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.