23

I am trying node.js selenium web driver example...

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
   usingServer('http://localhost:4444/wd/hub').
   withCapabilities(webdriver.Capabilities.chrome()).
   build();

driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
 return driver.getTitle().then(function(title) {
   return title === 'webdriver - Google Search';
 });
}, 1000);

driver.quit();

... but got error

promise.js:1542
      throw error;
            ^
UnknownError: 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
    at new bot.Error (/Users/maks/Dropbox/nodeApps/orgi/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)

I guessed to set PATH variable:

$ cat .bashrc

export PATH=$PATH:/usr/local/git/bin/
export PATH=$PATH:~/bin
export PATH=$PATH:~/Dropbox/chromedriver

And restart console, but got the same error.

Community
  • 1
  • 1
Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166

5 Answers5

44

Using selenium-server-standalone-*.jar from here, you can pass webdriver.chrome.driver property when launching it like so:

java -jar selenium-server-standalone-2.35.0.jar -Dwebdriver.chrome.driver="D:\dev\chromedriver.exe"

This eliminates the error; Java command line option -Dproperty=value sets a system property value as expected.

Oleg
  • 24,465
  • 8
  • 61
  • 91
6

Just in case some one getting this error :

Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -Dwebdrive

this thread might help :

Use Parameters before jar file

 java [-options] -jar jarfile [args...] (to execute a jar file)

So your command should be:

java -jar -Dwebdriver.chrome.driver="D:\dev\chromedriver.exe" selenium-server-standalone-2.35.0.jar 

Hope it helps someone in future.

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72
2

If you don't want to use the selenium server but just want to use the chromedriver directly, something like this will work:

var chrome = require('selenium-webdriver/chrome');
var service = new chrome.ServiceBuilder(__dirname + '/node_modules/.bin/chromedriver').build();
var driver = new chrome.createDriver(capabilities, service);

It's not very well documented, I had to poke around the source code a bit.

0

The simplest solution I found is to make the chromedriver file executable.

Incorrect:

**-rw-rw-r--** 1 user user  5560736 Jul 31 00:56 chromedriver

Correct:

**-rwxrwxr-x** 1 user user 58204704 Aug 14 08:18 phantomjs

Once chromedriver matched phantomjs it sprang to life

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
Paul Lockwood
  • 4,283
  • 1
  • 24
  • 19
-3

You can use the following code to set path in your code

System.setProperty("webdriver.chrome.driver", "your_path");

Path to be mentioned within quotes.

Community
  • 1
  • 1
user2525437
  • 155
  • 4