Skip to content

Instantly share code, notes, and snippets.

@joshuatz
Last active September 9, 2020 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuatz/93cd7798d20e26de0dc9e6795b71fdcb to your computer and use it in GitHub Desktop.
Save joshuatz/93cd7798d20e26de0dc9e6795b71fdcb to your computer and use it in GitHub Desktop.
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