Reputation: 19340
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
Upvotes: 33
Views: 59308
Reputation: 43
Just puth this -
require("chromedriver");
before this -
let driver = new webdriver.Builder().forBrowser('chrome').build();
Upvotes: 0
Reputation: 41
Just Download the driver .exe file into the same folder as your current project file is lying. It worked for me. Might work for you as well. Peace!
Upvotes: 4
Reputation: 1994
So here is how you can fix it
Following this link and download compatible driver as per your chrome version -
https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/
Once driver is downloaded place it somewhere in c:\ drive like c:\chromedriver
Add that path to your System environment variable - Reference is here https://www.browserstack.com/guide/run-selenium-tests-using-selenium-chromedriver
Once that is done please note to ensure to reboot your windows machine else Jenkins won't be able to find it
One more debug tip - I initially installed it using npm globally and added C:\Users\some_windows_user\AppData\Roaming\npm\node_modules to system environment variable and rebooted my machine. That never worked in CI.
So like I said above move it c:\chromedriver and add to System environment variable and 100% reboot you machine
Upvotes: 0
Reputation: 1277
To add to Niels' answer, for those not using Babel
npm install -g chromedriver
If PATH errors persist, just save it to the local project's dependencies
npm install --save-dev chromedriver
const webdriver = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); const chromedriver = require('chromedriver'); chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());
Upvotes: 48
Reputation: 2852
The easiest way for me is to use a local install of chromedriver. I got the error when I forgot to require chromedriver inside my script.
npm install
require('chromedriver');
before you call a webdriver (I am using it with selenium-webdriver
)Not sure why it's not detecting your global path. If I don't have the line require('chromedriver')
I can add the local chromedriver file to the path and it works.
Upvotes: 0
Reputation: 109
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
Upvotes: 10
Reputation: 191
for my small selenium-webdriver
test i did these steps after i researched online and here:
npm install selenium-webdriver
npm install chromedriver
npm install geckodriver
and opened file library.js and npm init
and ran node library.js
(source code below)Error:
(node:14212) UnhandledPromiseRejectionWarning: NoSuchSessionError: invalid session id
Some long error related to not same chromedriver version. so i checked the chrome browser version manually in the browser. it was version 73
and my mistake i had downloaded chromedriver version 74.0
.https://chromedriver.storage.googleapis.com/index.html?path=73.0.3683.68/
download according to your OS and download it in ~/Downloads
.terminal
in the ~/Downloads
folder.USER@DESKTOP:~/Downloads$ unzip ~/Downloads/chromedriver_linux64.zip -d ~/Downloads
You will get the raw chromedriver
file in ~/Downloads
folder.ChromeDriver 73.0.3683.68
file to two places - usr/local/bin
and usr/bin
in my system. chromedriver
file in usr/local/bin
.to move the file - USER@DESKTOP:~/Downloads$ sudo mv -f ~/Downloads/chromedriver /usr/local/bin/chromedriver
and USER@DESKTOP:~/Downloads$ sudo mv -f ~/Downloads/chromedriver /usr/bin/chromedriver
you are saying you want to move the file chromedriver from first location to other means replacing any files already in those locations with same name.
Last all i did was. close the vscode and relaunched it. and ran my code node library.js
. and it worked it the chrome browser for me.
SOURCE CODE : LIBRARY.JS
var webdriver = require('selenium-webdriver');
var By = webdriver.By;
var until = webdriver.until;
var driver = new webdriver.Builder().forBrowser('chrome').build();
driver.get('https://www.google.com');
Upvotes: 2
Reputation: 2045
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
Upvotes: 17