shefali ayachit
shefali ayachit

Reputation: 1

Null pointer exception Chrome Driver

Null pointer exception.

System.setProperty("webdriver.chrome.driver", System.getProperty("C:\\Users\\xxxxxx\\chromedriver_win32_2.1"));

ChromeDriver d1 = new ChromeDriver();

Hi All,

I am trying to automate ChromeDriver. But it is throwing this error. Can someone please help me?

Upvotes: 0

Views: 1805

Answers (2)

Petr Janeček
Petr Janeček

Reputation: 38414

System.setProperty("webdriver.chrome.driver", System.getProperty("C:\\Users\\xxxxxx\\chromedriver_win32_2.1"));

This is flat-out wrong. It should be

System.setProperty("webdriver.chrome.driver", "C:\\Users\\xxxxxx\\chromedriver_win32_2.1\\chromedriver.exe");

Notice that I dropped the System.getProperty() call which did nothing (returned null) and I added \\chromedriver.exe to your path since you need to provide a full path with the exucutable included (and the downloaded .zip file unpacked).

Upvotes: 2

Phoenix
Phoenix

Reputation: 1931

It could be one of two things:

  1. One of your setProperty arguments are null (either the key doesn't exist/typo, or the getProperty doesnt exist/typo
  2. Your getProperty method is using only one argument, so the system is expecting this to be the key. I doubt your property key is going to be a full directory, so you'll need to use the double argument getProperty(key, value).

Source: Get/Set Property

Upvotes: 0

Related Questions