【问题标题】:Using JavaScript's Selenium Webdriver, how to launch Chrome with a specific path to chrome.exe?使用 JavaScript 的 Selenium Webdriver,如何使用 chrome.exe 的特定路径启动 Chrome?
【发布时间】:2019-09-27 21:33:08
【问题描述】:

我有以下 Javascript 代码,它使用由 PATH 环境变量指定的 Chrome 路径来启动 Chrome。

    let driver = await new Builder()
        .forBrowser('chrome')
        .build();

如何使用特定的 Chrome 路径启动 Chrome?我会喜欢这样的:

    let driver = await new Builder()
        .forBrowser('chrome')
        .withPath('C:\\temp\\chrome.exe')
        .build();

【问题讨论】:

    标签: javascript typescript google-chrome selenium-webdriver


    【解决方案1】:

    您可能需要使用 ChromeOptions 来设置自定义 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();
    

    Documentation 用于 chrome.Options

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-14
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 2013-12-05
      • 2013-07-18
      相关资源
      最近更新 更多