安装我使用的chromedriver和selenium-webdriver npm install chromedriver -save npm install selenium-webdriver -save
运行此代码后,新的Chrome窗口会像Google一样打开:
var webDriver = require(‘selenium-webdriver’);
var chrome = require(‘selenium-webdriver/chrome’);
var path = require(‘chromedriver’).path;
var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
build();
driver.get(‘https://www.google.com’);
在我的mac上部署应用程序后,这是我得到的错误: 未捕获(承诺)错误:产生ENOTDIR
- 非常感谢,谢谢!
答案 0 :(得分:0)
您需要按照以下步骤操作:
安装selenium webdriver
npm install selenium-webdriver --save
下载chrome webdriver
ChromeDriver Home
安装chromedriver
npm install chromedriver --chromedriver_filepath = / Users / ** / chromedriver_mac64.zip
Javascript代码
const {Builder, By, Key, until, Capabilities} = require('selenium-webdriver');
console.log(require('chromedriver'));
var chromeCapabilities = Capabilities.chrome();
var chromeOptions = {
'args': ['--test-type', '--start-maximized'],
'prefs': {
'download.default_directory': '/Users/**/app/output/'
}
};
chromeCapabilities.set('chromeOptions', chromeOptions);
(async function example() {
let driver = await new Builder().forBrowser('chrome')
.withCapabilities(chromeCapabilities)
.build();
console.log(await driver.getCapabilities());
try {
await driver.get('http://www.google.com');
await driver.wait(until.elementLocated(By.id('lst-ib')), 20000);
} finally {
await driver.quit();
}
})();