WebDriverJS: Chrome profile


How do we set the Chrome profile for WebDriverJS (Selenium for Node.js)?

Prerequisites

First, you’ll need Chrome and ChromeDriver (you can following this video if you’re on Mac OS).

If you have homebrew installed, you can run the following:

# install the browser
$ brew cask install google-chrome

# install the driver
$ brew install chromedriver

Building your driver

Now you want to start building your driver. See how it’s done here.

Don’t forget to swap firefox with chrome:

builder.forBrowser('chrome');

Chrome options

Before instantiating the driver, you want to pass the profile as an argument in Chrome options:

const chrome = require('selenium-webdriver/chrome');
const options = new chrome.Options();
// replace `path/to/profile`
options.addArguments('user-data-dir=path/to/profile');

Note: ChromeDriver expects path/to/profile/Default/. If that’s not found, it will create the Default directory.

Now let’s update the builder so WebDriverJS launches Chrome based on the specified profile:

builder.forBrowser('chrome');
builder.setChromeOptions(options);

To confirm that the profile is correct, you can check the path in chrome://version:

const driver = builder.build();
driver.get('chrome://version');