node.js complaining that "The ChromeDriver could not be found on the current PATH" even though chromedriver is on the path
To add to Niels' answer, for those not using Babel
- 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-dev chromedriver
- 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());
I had the same issue. I have resolved it by taking the path from chromedriver package.
Here is my code:
import webdriver from 'selenium-webdriver';import chrome from 'selenium-webdriver/chrome';import chromedriver from 'chromedriver';chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());var driver = new webdriver.Builder() .withCapabilities(webdriver.Capabilities.chrome()) .build();
Which is based on the code from this answer: Passing require('chromedriver).path directly to selenium-webdriver
Might be a little late but if someone comes across this problem for me worked the following:
First npm install -g chromedriver --save
Then add this line on top of your code require('chromedriver');
Here is a demo:
require('chromedriver');var webdriver = require('selenium-webdriver');var driver = new webdriver.Builder() .forBrowser('chrome') .build();driver.get('https://google.com');
For more details you can go here: https://www.npmjs.com/package/chromedriver