Make sure you have the minimum dependencies (e.g. you have run yarn add selenium-webdriver
), and edit the file with your chromedriver bin info.
Last active
September 9, 2020 08:06
-
-
Save joshuatz/93cd7798d20e26de0dc9e6795b71fdcb to your computer and use it in GitHub Desktop.
Disable ChromeDriver messages to stdout with Selenium WebDriver & NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
const path = require('path'); | |
const { ServiceBuilder, Options: ChromeOptions } = require('selenium-webdriver/chrome'); | |
const webdriver = require('selenium-webdriver'); | |
async function main() { | |
// I'm doing this because I hate adding things to my PATH 😅 | |
// Normally, webdriver will automatically grab the EXE from PATH if you have followed a generic setup guide | |
const driverBinPath = path.normalize(`C:\\Users\\Joshua\\Downloads\\chromedriver_win32\\chromedriver.exe`); | |
const serviceBuilder = new ServiceBuilder(driverBinPath); | |
/** | |
* SOLUTION: | |
* By excluding the switch from defaults, this should disable the default logging | |
* @see https://bugs.chromium.org/p/chromedriver/issues/detail?id=2907#c3 | |
*/ | |
const chromeOptions = new ChromeOptions(); | |
chromeOptions.excludeSwitches('enable-logging'); | |
// Put everything together | |
const driver = await new webdriver.Builder() | |
.forBrowser('chrome') | |
.setChromeService(serviceBuilder) | |
.setChromeOptions(chromeOptions) | |
.build(); | |
// Let's try something | |
await driver.get(`https://example.com`); | |
const title = await driver.getTitle(); | |
return title; | |
} | |
main().then(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment