简体   繁体   English

NodeJS Selenium 如何设置webdriver的相对路径?

[英]NodeJS Selenium how to set relative path to webdriver?

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我将在另一台计算机上运行脚本,因此设置环境变量不是更好的解决方案

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不要忘记运行npm i --save chromedriver

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM