-2
public class Login 
{
    static WebDriver driver = new ChromeDriver();   
    @SuppressWarnings("resource")
    public static void main(String[] args) throws InterruptedException 
    {

        System.setProperty("webdriver.chrome.driver","C:\\Users\\MMFD-3\\MYData\\chromedriver.exe");    
        String baseUrl = "https://stackoverflow.com/";                  
        driver.get(baseUrl);
    }
}

Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: 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:754) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134) 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:355) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at newpacakge.Login.(Login.java:14)

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Please add your code otherwise there will be no idea what is going wrong in this. Please add what steps you've taken to fix this error. – demouser123 Nov 18 '19 at 07:38
  • 2
    Does this answer your question? [Getting "The path to the driver executable must be set by the webdriver.chrome.driver system property"though set correct path](https://stackoverflow.com/questions/44476647/getting-the-path-to-the-driver-executable-must-be-set-by-the-webdriver-chrome-d) – demouser123 Nov 18 '19 at 07:38
  • Have you tried using the link in the error? – OneCricketeer Nov 18 '19 at 07:41
  • Does this answer your question? [How to set Google Chrome in WebDriver](https://stackoverflow.com/questions/16689426/how-to-set-google-chrome-in-webdriver) – frianH Nov 18 '19 at 07:42
  • What is the question?????????????? – Antoniossss Nov 18 '19 at 08:15
  • @demouser123 I did what you are saying but it won't work for me. – Shikha Garewal Nov 18 '19 at 08:27

2 Answers2

0

You are creating an instance of ChromeDriver before setting the property. Can you try after making following changes:

public class Login 
{
    static WebDriver driver;   
    @SuppressWarnings("resource")
    public static void main(String[] args) throws InterruptedException 
    {

        System.setProperty("webdriver.chrome.driver","C:\\Users\\MMFD-3\\MYData\\chromedriver.exe");
        driver = new ChromeDriver();    
        String baseUrl = "https://stackoverflow.com/";                  
        driver.get(baseUrl);
    }
}

And make sure the chrome driver version is matching with your chrome version

Ayaz
  • 249
  • 1
  • 2
  • 11
0

This error message...

Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: 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.

...implies that your program was unable to locate the chromedriver excutable.


Seems you were pretty close. Within the class defination, you can of coarse declare the WebDriver instance as follows:

static WebDriver driver;

But you mustn't instantiate it as you did:

static WebDriver driver = new ChromeDriver(); 

Unless you specifically mention the absolute path of the chromedriver executable.


Solution

You need to separate the initialization part from the declaration:

static WebDriver driver;

Initialize the webdriver as a instance of ChromeDriver() later as follows:

System.setProperty("webdriver.chrome.driver","C:\\Users\\MMFD-3\\MYData\\chromedriver.exe");  
String baseUrl = "https://stackoverflow.com/";
driver = new ChromeDriver();
driver.get(baseUrl);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352