tl;dr: Does anyone know how to pass the path of chromedriver to selenium-webdriver in code without setting the PATH environment variable?
I'm attempting to use selenium-webdriver with chrome, but would prefer to not physically install chromedriver and manipulate the path. I have the following code:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
Without chromedriver set in the path, this throws the 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.
I'd prefer not have to setup my path, so I've installed chromedriver from npm and added to my package.json:
"scripts": {
"preinstall-chromedriver": "npm install",
"install-chromedriver": "node node_modules/chromedriver/install.js",
"pretest_e2e": "npm run install-chromedriver",
"test_e2e": "node release/test/rune2e.js"
},
Now I have chromedriver installed and can get the path with require('chromedriver').path
, but I have no way of passing this to the selenium-webdriver. Anyone know?
For Windows, Allow Read & Execute Permissions on chromedriver.exe for Everyone: Right Click chromedriver.exe > Properties On ChromeDriver.
As Google Chrome dominates the browser market, the use of a ChromeDriver becomes a must. Selenium WebDriver uses the ChromeDriver to communicate test scripts with Google Chrome.
ChromeDriver expects you to have Chrome installed in the default location for your platform.
You need to create & set your own default chrome service.
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();
You can also do this:
require('chromedriver');
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With