Home > Blockchain >  NodeJS Selenium how to set relative path to webdriver?
NodeJS Selenium how to set relative path to webdriver?

Time:11-30

Now i have those 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 will run script at another computer, so setting environment variable not better solution

CodePudding user response:

You can download the script into your project directory and use

let options = new Options();
const path = join(__dirname, './yourdriver')
options.setBinary(path)
let builder = new Builder().forBrowser('chrome')
builder = builder.setChromeOptions(options)
let driver = await builder.build();

Else

let webdriver = require('selenium-webdriver');
let chrome = require('selenium-webdriver/chrome');
let path = require('chromedriver').path;
let service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();

Dont forget to run npm i --save chromedriver

  • Related