selenium-webdriver/chrome

Defines a WebDriver client for the Chrome web browser. Before using this module, you must download the latest ChromeDriver release and ensure it can be found on your system PATH.

There are three primary classes exported by this module:

  1. ServiceBuilder: configures the remote.DriverService that manages the ChromeDriver child process.

  2. Options: defines configuration options for each new Chrome session, such as which proxy to use, what extensions to install, or what command-line switches to use when starting the browser.

  3. Driver: the WebDriver client; each new instance will control a unique browser session with a clean user profile (unless otherwise configured through the Options class).

    let chrome = require('selenium-webdriver/chrome'); let {Builder} = require('selenium-webdriver');

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

Customizing the ChromeDriver Server

By default, every Chrome session will use a single driver service, which is started the first time a Driver instance is created and terminated when this process exits. The default service will inherit its environment from the current process and direct all output to /dev/null. You may obtain a handle to this default service using getDefaultService() and change its configuration with setDefaultService().

You may also create a Driver with its own driver service. This is useful if you need to capture the server's log output for a specific session:

let chrome = require('selenium-webdriver/chrome');

let service = new chrome.ServiceBuilder()
    .loggingTo('/my/log/file.txt')
    .enableVerboseLogging()
    .build();

let options = new chrome.Options();
// configure browser options ...

let driver = chrome.Driver.createSession(options, service);

Users should only instantiate the Driver class directly when they need a custom driver service configuration (as shown above). For normal operation, users should start Chrome using the selenium-webdriver.Builder.

Working with Android

The ChromeDriver supports running tests on the Chrome browser as well as WebView apps starting in Android 4.4 (KitKat). In order to work with Android, you must first start the adb

adb start-server

By default, adb will start on port 5037. You may change this port, but this will require configuring a custom server that will connect to adb on the correct port:

let service = new chrome.ServiceBuilder()
    .setAdbPort(1234)
    build();
// etc.

The ChromeDriver may be configured to launch Chrome on Android using Options#androidChrome():

let driver = new Builder()
    .forBrowser('chrome')
    .setChromeOptions(new chrome.Options().androidChrome())
    .build();

Alternatively, you can configure the ChromeDriver to launch an app with a Chrome-WebView by setting the androidActivity option:

let driver = new Builder()
    .forBrowser('chrome')
    .setChromeOptions(new chrome.Options()
        .androidPackage('com.example')
        .androidActivity('com.example.Activity'))
    .build();

[Refer to the ChromeDriver site] for more information on using the ChromeDriver with Android.

Classes

Driver
Options
ServiceBuilder