Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote Webdriver Chrome throws a "path to the driver executable" error

Hi when i use the following code

IWebDriver _webDriver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
                DesiredCapabilities.Chrome());

I get the follwing error

System.InvalidOperationException : 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 TearDown : System.NullReferenceException : Object reference not set to an instance of an object. at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at Testframework.Browser.RemoteGoto(String browser, String url) in Browser.cs: line 86 at Testframework.CommonAction.RemoteBrowser(String browser) in CommonAction.cs: line 70 at Test.RegistrationTest.InvalidRegistrationTest(String browser, String username, String password, String confirmPassword, String securityQuestion, String securityAnswer, String errorMessageText, String firstname, String lastname) in RegistrationTest.cs: line 50 --TearDown at Testframework.CommonAction.CaptureScreen(String fileName) in CommonAction.cs: line 121 at Test.RegistrationTest.SnapshotOnFailure() in RegistrationTest.cs: line 590

like image 589
Anand S Avatar asked Feb 17 '23 08:02

Anand S


2 Answers

The clue really is in the error.

Chrome should be installed on the system where the tests are either running on or being pointed to.

Take a step back, look at the documentation:

https://code.google.com/p/selenium/wiki/ChromeDriver

Also, if Chrome is installed in a peculiar place, you'll need to point Selenium to it's location. Again, this is explained in the documentation.

In C#:

DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability("chrome.binary", this.binaryLocation);

or:

ChromeOptions options = new ChromeOptions();
options.BinaryLocation = "pathtogooglechrome";
capabilities.SetCapability(ChromeOptions.Capability, options);
like image 134
Arran Avatar answered Feb 19 '23 23:02

Arran


Instead of changing the code you can have other way round.
Download the chrome driver and set the PATH environment variable pointing to the directory where the chromedriver.exe is present.

Restart your IDE / Command console and run the tests. It works!!!

like image 41
Harshavardhan Konakanchi Avatar answered Feb 19 '23 23:02

Harshavardhan Konakanchi