Skip to content

Instantly share code, notes, and snippets.

@joshuatz
Last active Sep 9, 2020
Embed
What would you like to do?
Disable ChromeDriver messages to stdout with Selenium WebDriver & NodeJS

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.

Here is a full writeup

// @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