安装官网提示的安装步骤进行安装并开始启动时报如下错误
The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver fromhttp://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.
当时反复确认自己的代码和环境变量配置无误后,就直接看源码了
代码如下
const { Builder } = require('selenium-webdriver');
const { suite } = require('selenium-webdriver/testing');
const chrome = require('selenium-webdriver/chrome');
suite(function(env) {
describe('Open Chrome', function() {
let driver;
before(async function() {
let options = new chrome.Options();
driver = await new Builder()
.setChromeOptions(options)
.forBrowser('chrome')
.build();
});
// after(() => driver.quit());
it('Basic Chrome test', async function() {
await driver.get('https://www.baidu.com');
});
});
});
环境变量如下
在源码中找到 locateSynchronously()函数并进行debug发现原来是 环境变量未更新 所以解决方案时重启电脑或者重启node即可