java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;

1,070 views
Skip to first unread message

MCD dotCom

unread,
May 8, 2020, 7:59:45 PM5/8/20
to Selenium Users
Hello, 

I have this below code:

package DDT;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class WordpressLogin {

@Test(dataProvider="login")
public void loginMySite(String uName, String pass) throws InterruptedException
{
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver",".......\\resources\\chromedriver.exe");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

}

@DataProvider(name="login")
public Object[][] passData()
{
Object[][] data = new Object[2][2];
data[0][0] = "test1";
data[0][1] = "Welcome123@";
data[1][0] = "test2";
data[1][1] = "Welcome123@";
return data;
}
}

I get this error:

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


How can I fix it?

Thank you!

⇜Krishnan Mahadevan⇝

unread,
May 9, 2020, 12:38:04 PM5/9/20
to Selenium Users
Flip the order of these two lines in your code

WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver",".......\\resources\\chromedriver.exe");



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/86aeb510-c5fd-4041-bb27-2365f99a5e4a%40googlegroups.com.

MCD dotCom

unread,
May 9, 2020, 3:26:42 PM5/9/20
to Selenium Users
Thanks, it worked!

Now I have this inside the method and it worked:
System.setProperty("webdriver.chrome.driver",".......\\resources\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

After that, I moved the two lines of code outside the method as global variable and i get syntax error. How can I fix it?

To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.
1.png

Krishnan Mahadevan

unread,
May 9, 2020, 3:32:04 PM5/9/20
to seleniu...@googlegroups.com

You can try including System.setProperty("webdriver.chrome.driver",".......\\resources\\chromedriver.exe");

Inside a static block.

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d5b08189-f876-44db-8880-c8bf6b2475b1%40googlegroups.com.

MCD dotCom

unread,
May 9, 2020, 4:29:55 PM5/9/20
to seleniu...@googlegroups.com
It worked.

 static {

System.setProperty("webdriver.chrome.driver",".......\\resources\\chromedriver.exe");  
}

If you could please clarify why it did not work without static and why it worked with static, it would be helpful. 

Thanks!

You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/iMD9JNnjcxU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/EA8AAD7E-4937-405D-A0E7-C39CCD648E83%40gmail.com.


--
Reply all
Reply to author
Forward
0 new messages