4

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

Anand S
  • 760
  • 5
  • 13
  • 28

2 Answers2

4

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);
Arran
  • 24,648
  • 6
  • 68
  • 78
  • Hi , i am able to find only java examples , can you tell me how to set the path of the chrome in C# webdriver remote , since i am not able to find a equivalent in C#q – Anand S Mar 04 '13 at 11:35
  • Thank u , This is the path i set options.BinaryLocation = @"..\RequiredFiles\chromedriver_win_26.0.1383.0\chromedriver.exe"; i am getting the following error "The path to the driver executable must be set by the webdriver.chrome.driver system property" – Anand S Mar 04 '13 at 13:03
  • Tried this System.Environment.SetEnvironmentVariable("webdriver.chrome.driver",@"/path/to/where/you/ve/put/chromedriver.exe") which C# equivalent java System.setProperty("webdriver.chrome.driver","/path/to/where/you/ve/put/chromedriver.exe"); which did not work – Anand S Mar 04 '13 at 13:42
  • If you use the ChromeDriver directly (look at the documentation), does it launch Chrome OK? – Arran Mar 04 '13 at 19:01
  • Yes when i do this "ChromeDriver(ChromeDriverpath)" it works but i am not able to set the chromedriverpath in the remote webdriver.I have no idea why – Anand S Mar 05 '13 at 08:08
4

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!!!

Harshavardhan Konakanchi
  • 4,238
  • 6
  • 36
  • 54
  • Thank u is there any other way other than setting it up as environment variable . i also found this solution setting up the chromedriver path when launching the console(java -Dwebdriver.chrome.driver=C:\example\chromedriver.exe -jar selenium-server-standalone-2.31.0.jar). I want to avoid this solution as much as possible and set the path in code so the code remains portable :) – Anand S Mar 05 '13 at 08:13
  • @AnandS To maintain the code as portable it's better if we had not hardcoded the location of the driver. I prefer setting path, as the developed tests can be ported on to any machine and can be used just by setting the PATH – Harshavardhan Konakanchi Mar 05 '13 at 09:03
  • Thank u , I am very curious to know why when i use this System.Environment.SetEnvironmentVariable("webdriver.chrome.driver",@"/path/to/w‌​here/you/ve/put/chromedriver.exe") the chromedriver.exe is not getting set a environmental variable – Anand S Mar 05 '13 at 10:09