node.js complaining that "The ChromeDriver could not be found on the current PATH" even though chromedriver is on the path

Dave picture Dave · Apr 4, 2016 · Viewed 21.2k times · Source

I’m using node 5.10.0 on Linux. Having some issues running my script, which are displayed below

[davea@mydevbox mydir]$ node SkyNet.js 
Validation Complete
/home/davea/node_modules/selenium-webdriver/chrome.js:185
      throw Error(
      ^

Error: The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and   ensure it can be found on your PATH.
    at Error (native)
    at new ServiceBuilder (/home/davea/node_modules/selenium-webdriver/chrome.js:185:13)
    at getDefaultService (/home/davea/node_modules/selenium-webdriver/chrome.js:362:22)
    at Driver (/home/davea/node_modules/selenium-webdriver/chrome.js:771:34)
    at Builder.build (/home/davea/node_modules/selenium-webdriver/builder.js:464:16)
    at Object.<anonymous> (/home/davea/mydir/js/Optimus.js:14:4)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)

It is saying chromedriver isn’t on my path, but I just downloaded the appropriate version from here — http://chromedriver.storage.googleapis.com/index.html?path=2.9/ , and as you can see, it is on my PATH

[davea@mydevbox mydir]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/davea/bin:/home/davea/bin:/usr/lib/chromedriver

with the following permissions …

[davea@mydevbox mydir]$ ls -al /usr/lib/chromedriver
-rwxr-xr-x 1 davea evotext 5503600 Feb  3  2014 /usr/lib/chromedriver

So I am confused as to why I’m getting this error. Any help is appreciated, - Dave

Answer

Nick Mitchell picture Nick Mitchell · May 6, 2017

To add to Niels' answer, for those not using Babel

  1. First install the chromedrive package using npm. If you install globally ensure to have node packages in your path
npm install -g chromedriver

If PATH errors persist, just save it to the local project's dependencies

npm install --save chromedriver
  1. For those not using Babel
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');

chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());