1.全局安装chromedrive包
1
| npm install -g chromedriver
|
如果环境变量PATH配置错误,只需要在本地项目安装chromedriver包
1
| npm install --save-dev chromedriver
|
新建index.js
1 2 3 4 5 6 7 8 9 10 11
| import webdriver from 'selenium-webdriver'; import chrome from 'selenium-webdriver/chrome'; import chromedriver from 'chromedriver';
chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());
var driver = new webdriver.Builder() .withCapabilities(webdriver.Capabilities.chrome()) .build();
driver.get('http://www.baidu.com');
|
参考文档
The ChromeDriver could not be found on the current PATH
node+selenium-webdriver爬虫高级