# Class Builder

code »

Creates new `WebDriver` instances. The environment variables listed below may be used to override a builder's configuration, allowing quick runtime changes.

- `SELENIUM_REMOTE_URL`: defines the remote URL for all builder instances. This environment variable should be set to a fully qualified URL for a WebDriver server (e.g. http://localhost:4444/wd/hub).
- `SELENIUM_BROWSER`: defines the target browser in the form `browser[:version][:platform]`.

Suppose you had mytest.js that created WebDriver with `var driver = new webdriver.Builder().build();`. This test could be made to use Firefox on the local machine by running with `SELENIUM_BROWSER=firefox node mytest.js`.

Alternatively, you could request Chrome 36 on Linux from a remote server with `SELENIUM_BROWSER=chrome:36:LINUX SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub node mytest.js`.

## Constructor

Builder ( )
Show:Public Protected Private

## Instance Methods

code »build ( ) ⇒ `!webdriver.WebDriver`

Creates a new WebDriver client based on this builder's current configuration.

Returns

A new WebDriver instance.

Throws

`Error`
  If the current configuration is invalid.

code »forBrowser ( name, opt_version, opt_platform ) ⇒ `!Builder`

Configures the target browser for clients created by this instance. Any calls to `#withCapabilities` after this function will overwrite these settings.

You may also define the target browser using the `SELENIUM_BROWSER` environment variable. If set, this environment variable should be of the form `browser[:[version][:platform]]`.

Parameters

name: `(string|webdriver.Browser)`
  The name of the target browser; common defaults are available on the `webdriver.Browser` enum.
opt_version: `string=`
  A desired version; may be omitted if any version should be used.
opt_platform: `string=`
  The desired platform; may be omitted if any version may be used.

Returns

A self reference.

code »getCapabilities ( ) ⇒ `!webdriver.Capabilities`

Returns the base set of capabilities this instance is currently configured to use.

Returns

The current capabilities for this builder.

code »getServerUrl ( ) ⇒ `string`

Returns

The URL of the WebDriver server this instance is configured to use.

code »setAlertBehavior ( behavior ) ⇒ `!Builder`

Sets the default action to take with an unexpected alert before returning an error.

Parameters

behavior

Returns

A self reference.

code »setChromeOptions ( options ) ⇒ `!Builder`

Sets Chrome-specific options for drivers created by this builder. Any logging or proxy settings defined on the given options will take precedence over those set through `#setLoggingPrefs` and `#setProxy`, respectively.

Parameters

options: `!chrome.Options`
  The ChromeDriver options to use.

Returns

A self reference.

code »setControlFlow ( flow ) ⇒ `!Builder`

Sets the control flow that created drivers should execute actions in. If the flow is never set, or is set to `null`, it will use the active flow at the time `#build()` is called.

Parameters

flow: `webdriver.promise.ControlFlow`
  The control flow to use, or `null` to

Returns

A self reference.

code »setEnableNativeEvents ( enabled ) ⇒ `!Builder`

Sets whether native events should be used.

Parameters

enabled: `boolean`
  Whether to enable native events.

Returns

A self reference.

code »setFirefoxOptions ( options ) ⇒ `!Builder`

Sets Firefox-specific options for drivers created by this builder. Any logging or proxy settings defined on the given options will take precedence over those set through `#setLoggingPrefs` and `#setProxy`, respectively.

Parameters

options: `!firefox.Options`
  The FirefoxDriver options to use.

Returns

A self reference.

code »setLoggingPrefs ( prefs ) ⇒ `!Builder`

Sets the logging preferences for the created session. Preferences may be changed by repeated calls, or by calling `#withCapabilities`.

Parameters

prefs: `!(webdriver.logging.Preferences|Object.<string, string>)`
  The desired logging preferences.

Returns

A self reference.

code »setProxy ( config ) ⇒ `!Builder`

Sets the proxy configuration to use for WebDriver clients created by this builder. Any calls to `#withCapabilities` after this function will overwrite these settings.

Parameters

config: `!webdriver.ProxyConfig`
  The configuration to use.

Returns

A self reference.

code »setScrollBehavior ( behavior ) ⇒ `!Builder`

Sets how elements should be scrolled into view for interaction.

Parameters

behavior: `number`
  The desired scroll behavior: either 0 to align with the top of the viewport or 1 to align with the bottom.

Returns

A self reference.

code »usingServer ( url ) ⇒ `!Builder`

Sets the URL of a remote WebDriver server to use. Once a remote URL has been specified, the builder direct all new clients to that server. If this method is never called, the Builder will attempt to create all clients locally.

As an alternative to this method, you may also set the `SELENIUM_REMOTE_URL` environment variable.

Parameters

url: `string`
  The URL of a remote server to use.

Returns

A self reference.

code »withCapabilities ( capabilities ) ⇒ `!Builder`

Sets the desired capabilities when requesting a new session. This will overwrite any previously set capabilities.

Parameters

capabilities: `!(Object|webdriver.Capabilities)`
  The desired capabilities for a new session.

Returns

A self reference.

## Instance Properties

code »capabilities_ : `!webdriver.Capabilities`
code »chromeOptions_ : `chrome.Options`
code »firefoxOptions_ : `firefox.Options`
code »flow_ : `webdriver.promise.ControlFlow`
code »url_ : `string`