Reputation: 3755
Tried with "npm install selenium-webdriver" I'm still getting the error below. Any idea where the path is sops to be at?
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 (<anonymous>)
at new ServiceBuilder (/var/www/nodejs/node_modules/selenium-webdriver/chrome.js:51:11)
at getDefaultService (/var/www/nodejs/node_modules/selenium-webdriver/chrome.js:216:22)
at new Driver (/var/www/nodejs/node_modules/selenium-webdriver/chrome.js:470:32)
at Builder.build (/var/www/nodejs/node_modules/selenium-webdriver/builder.js:302:14)
at Object.handle (/var/www/nodejs/node.js:31:4)
at next_layer (/var/www/nodejs/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/var/www/nodejs/node_modules/express/lib/router/route.js:107:5)
at c (/var/www/nodejs/node_modules/express/lib/router/index.js:195:24)
at Function.proto.process_params (/var/www/nodejs/node_modules/express/lib/router/index.js:251:12)
Upvotes: 20
Views: 58986
Reputation: 133
In my case, my terminal was already opened before I set PATH. All solutions failed until I finally restarted the terminal.
Upvotes: 0
Reputation: 31
You can put the browser driver in the same location that you store your code for execution.
Hope it helps
Upvotes: 3
Reputation: 1325
I wanted to have chromedriver downloaded with my npm install
command so I installed chromedriver
from npm by
npm install --save chromedriver
but then I was left with the question of how to set the path and I ended up in this question.
If you use this method as well, according with the npm-chromedriver docs you can do
require('chromedriver');
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
It does work as expected for me, notice that chromedriver is not imported by assigning the require
result to a variable but just as is
Upvotes: 5
Reputation: 986
You only need to install npm install selenium-webdriver
. Then download the chromedriver from here.
const path = require('path');
const { ServiceBuilder } = require('selenium-webdriver/chrome');
const { Builder } = require('selenium-webdriver');
const geckoDriverPath = path.join(__dirname, "geckodriver"); // or wherever you've your geckodriver
const serviceBuilder = new ServiceBuilder(geckoDriverPath);
const SeleniumDriver = await new Builder()
.forBrowser('chrome')
.setFirefoxService(serviceBuilder)
.build();
Upvotes: 4
Reputation: 321
Even after adding the driver path in the System variables it didnt worked.
But by creating & setting own default chrome service, it worked
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var path = require('chromedriver').path;
var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
Upvotes: 17
Reputation: 1
Under MacOSX the issue is likely to be caused by a wrong expansion of ~ to the hme directory. Set an absolute path instead of relying upon ~ and it works; at least on my computer.
Upvotes: -2
Reputation: 1148
Ok assuming you are using Windows please try the following steps:
Download the latest version of ChromeDriver from here ChromeDriver
Extract the zip and place the contents somewhere you know where it is for example "C:\Users\UserName\AppData\ChromeDriver"
Go to your Control Panel -> System -> Edit the System Variables. Click on the "environment variables" button.
In the system variables box there will be a variable named "Path" select it and click edit. Copy and paste the path to the containing directory of the chromedriver.exe you downloaded onto the end of the variable value and end it with a semi-colon.
Click ok and again to close environment variables and again to close system properties.
Close and reopen your terminal window.
Run the command again.
I hope this helps - there is a good tutorial here
Upvotes: 40