Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Google Chrome in WebDriver

I am trying to set Chrome as my browser for testing with Web-Driver and set the chromedriver.exe file properly but I am still getting the following error:

org.openqa.selenium.WebDriverException: 
The path to the driver executable must be set by the webdriver.chrome.driver system property; 
for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. 
The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list

I have already checked the path of the driver but still i am getting same error.
I don't know where i have made a mistake.

Here is my code:

File file = new File("C:\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Capability= DesiredCapabilities.chrome();
Capability.setBrowserName("chrome");
Capability.setPlatform(Platform.LINUX);

browser=new RemoteWebDriver(new URL(nodeURL),Capability);
browser.get(webUrl);

Please help me!!

like image 941
Kapil Avatar asked May 22 '13 10:05

Kapil


People also ask

Does Selenium WebDriver work with Chrome?

Setting up your system to allow a browser to be automated. Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, and Safari.

How do I change Chrome properties in Selenium?

Initially, you need to set the path to the chromedriver.exe file using set property method since you are using Chrome Browser for testing. You need to set the path to CRX File to add extensions method. Then you need to create an object of Chrome Desired Capabilities in Selenium class and pass it to web driver instance.

What is WebDriverManager ChromeDriver () setup ()?

WebDriverManager makes it easy and convert the manual stuff into automation. It verifies the version of the browser(eg chrome, firefox, Edge etc.) installed in your local machine by its own. It also uses the latest version of the driver(chromedriver, geckodriver etc.)


2 Answers

Aditya,

As you said in your last comment that you are trying to access chrome of some other system so based on that you should keep your chrome driver in that system itself.

for example: if you are trying to access linux chrome from windows then you need to put your chrome driver in linux at some place and give permission as 777 and use below code at your windows system.

System.setProperty("webdriver.chrome.driver", "\\var\\www\\Jar\\chromedriver");
Capability= DesiredCapabilities.chrome();   Capability.setPlatform(org.openqa.selenium.Platform.ANY);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);

This is working code of my system.

like image 125
Minal K Sinha Avatar answered Oct 11 '22 20:10

Minal K Sinha


I'm using this since the begin and it always work. =)

System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
like image 27
e1che Avatar answered Oct 11 '22 20:10

e1che