(一)初始化环境
乙醇 创建于 over 7 years 之前
最后更新: less than a minute 之前
阅读数: 193
MacOS
- nodejs版本: 6.2.0
- selenium-webdriver版本: 3.4.0
- chrome版本: 版本 59.0.3071.86(正式版本)64位
- chrome driver版本: ChromeDriver 2.30.477690
Windows
TODO
安装nodejs
TODO
安装selenium webdriver
mkdir se
cd se
cnpm install selenium-webdriver
[selenium-webdriver@*] installed at node_modules/.npminstall/selenium-webdriver/3.4.0/selenium-webdriver (20 packages, use 4s, speed 447.48kB/s, json 34.34kB, tarball 1.54MB)
All packages installed (20 packages installed from npm registry, use 4s, speed 446kB/s, json 22(34.34kB), tarball 1.54MB)
安装chrome driver
chrome driver建议通过科学上网的方式下载。
下载完成后请将chromedriver.exe(windows)放到系统PATH中
验证chrome driver是否正确安装,请在命令行中输入
chromedriver -h
Usage: chromedriver [OPTIONS]
Options
--port=PORT port to listen on
--adb-port=PORT adb server port
--log-path=FILE write server log to file instead of stderr, increases log level to INFO
--verbose log verbosely
--version print the version number and exit
--silent log nothing
--url-base base URL path prefix for commands, e.g. wd/url
--port-server address of server to contact for reserving a port
--whitelisted-ips comma-separated whitelist of remote IPv4 addresses which are allowed to connect to ChromeDriver
如能看到上述结果则证明安装成功
简单的环境验证测试
新建文件start.js,并键入下面的内容。
// start.js
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().forBrowser('chrome').build();
driver.get('http://itest.info');
console.log('quit driver');
driver.quit();
在命令行中运行
node strat.js
预期结果: chrome打开并跳转到itest.info首页,然后chrome正常退出。