使用JavaScript的Selenium Webdriver,如何使用特定的chrome.exe路径启动Chrome? [英] Using JavaScript's Selenium Webdriver, how to launch Chrome with a specific path to chrome.exe?
本文介绍了使用JavaScript的Selenium Webdriver,如何使用特定的chrome.exe路径启动Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下Javascript代码,可使用环境变量PATH
指定的Chrome路径启动Chrome.
I have the following Javascript code that launches Chrome with the path to Chrome specified by the PATH
environment variable.
let driver = await new Builder()
.forBrowser('chrome')
.build();
如何启动具有特定路径的Chrome浏览器?我会喜欢这样的东西:
How can I launch Chrome with a specific path to Chrome? I would love something like this:
let driver = await new Builder()
.forBrowser('chrome')
.withPath('C:\\temp\\chrome.exe')
.build();
推荐答案
您可能需要使用ChromeOptions设置自定义chrome.exe
You'll probably need to use ChromeOptions to setup custom chrome.exe
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const builder = new webdriver.Builder().forBrowser('chrome');
const chromeOptions = new chrome.Options();
chromeOptions.setChromeBinaryPath("/path/to/chrome.exe");
builder.setChromeOptions(chromeOptions);
const driver = builder.build();
的 文档 em> chrome.Options Documentation for chrome.Options 这篇关于使用JavaScript的Selenium Webdriver,如何使用特定的chrome.exe路径启动Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文