简体   繁体   中英

Using JavaScript's Selenium Webdriver, how to launch Chrome with a specific path to chromedriver.exe?

I have the following Javascript code that launches Chrome with the path to chromedriver.exe specified by the PATH environment variable. This question is different than how to launch Chrome with a specific chrome.exe because chromedriver.exe is a standalone server that takes in commands from Selenium Server and uses JSON commands to talk to the Chrome browser's API. You need both chrome.exe and chromedriver.exe to launch a Chrome browser with Selenium.

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

However, I would like to clear my PATH environment variable and instead set a path from within the code that launches Chrome, something like the below. How can I do that please?

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

In reading https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/chrome.js

At line 212

It seem posible to set in your environ variables a value for CHROMEDRIVER_EXE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM