现在我有这些错误:
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.
我将在另一台计算机上运行脚本,所以设置环境变量不是更好的解决方案
您可以将脚本下载到项目目录中并使用
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();
其他
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();
不要忘记运行npm i --save chromedriver