selenium-webdriver/firefox

Defines the WebDriver client for Firefox. Before using this module, you must download the latest geckodriver release and ensure it can be found on your system PATH.

Each FirefoxDriver instance will be created with an anonymous profile, ensuring browser historys do not share session data (cookies, history, cache, offline storage, etc.)

Customizing the Firefox Profile

The profile used for each WebDriver session may be configured using the Options class. For example, you may install an extension, like Firebug:

const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

let options = new firefox.Options()
    .addExtensions('/path/to/firebug.xpi')
    .setPreference('extensions.firebug.showChromeErrors', true);

let driver = new Builder()
    .forBrowser('firefox')
    .setFirefoxOptions(options)
    .build();

The Options class may also be used to configure WebDriver based on a pre-existing browser profile:

let profile = '/usr/local/home/bob/.mozilla/firefox/3fgog75h.testing';
let options = new firefox.Options().setProfile(profile);

The FirefoxDriver will never modify a pre-existing profile; instead it will create a copy for it to modify. By extension, there are certain browser preferences that are required for WebDriver to function properly and they will always be overwritten.

Using a Custom Firefox Binary

On Windows and MacOS, the FirefoxDriver will search for Firefox in its default installation location:

  • Windows: C:\Program Files and C:\Program Files (x86).
  • MacOS: /Applications/Firefox.app

For Linux, Firefox will always be located on the PATH: $(where firefox).

You can provide a custom location for Firefox by setting the binary in the Options:setBinary method.

const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

let options = new firefox.Options() .setBinary('/my/firefox/install/dir/firefox'); let driver = new Builder() .forBrowser('firefox') .setFirefoxOptions(options) .build();

Remote Testing

You may customize the Firefox binary and profile when running against a remote Selenium server. Your custom profile will be packaged as a zip and transferred to the remote host for use. The profile will be transferred once for each new session. The performance impact should be minimal if you've only configured a few extra browser preferences. If you have a large profile with several extensions, you should consider installing it on the remote host and defining its path via the Options class. Custom binaries are never copied to remote machines and must be referenced by installation path.

const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

let options = new firefox.Options()
    .setProfile('/profile/path/on/remote/host')
    .setBinary('/install/dir/on/remote/host/firefox');

let driver = new Builder()
    .forBrowser('firefox')
    .usingServer('http://127.0.0.1:4444/wd/hub')
    .setFirefoxOptions(options)
    .build();

Classes

AddonFormatError
Channel
Driver
Options
ServiceBuilder

Members

(inner, constant) Context :string

Enum of available command contexts.

Command contexts are specific to Marionette, and may be used with the #context= method. Contexts allow you to direct all subsequent commands to either "content" (default) or "chrome". The latter gives you elevated security permissions.

Type:
  • string
Properties
NameTypeDescription
CONTENTstring
CHROMEstring

(inner, constant) ExtensionCommand :string

Type:
  • string
Properties
NameTypeDescription
GET_CONTEXTstring
SET_CONTEXTstring
INSTALL_ADDONstring
UNINSTALL_ADDONstring
FULL_PAGE_SCREENSHOTstring

Methods

(async, inner) buildProfile(templatenullable, extensionsnon-null) → (non-null) {Promise.<string>}

Parameters:
NameTypeAttributesDescription
templatestring<nullable>

path to an existing profile to use as a template.

extensionsArray.<string>

paths to extensions to install in the new profile.

Returns:

a promise for the base64 encoded profile.

Type: 
Promise.<string>

(inner) configureExecutor(executornon-null)

Configures the given executor with Firefox-specific commands.

Parameters:
NameTypeDescription
executorhttp.Executor

the executor to configure.

(inner) createExecutor(serverUrlnon-null) → (non-null) {command.Executor}

Creates a command executor with support for Marionette's custom commands.

Parameters:
NameTypeDescription
serverUrlPromise.<string>

The server's URL.

Returns:

The new command executor.

Type: 
command.Executor

(inner) findInProgramFiles(file) → (non-null) {Promise.<?string>}

Parameters:
NameTypeDescription
filestring

Path to the file to find, relative to the program files root.

Returns:

A promise for the located executable. The promise will resolve to {@code null} if Firefox was not found.

Type: 
Promise.<?string>

(async, inner) installExtension(extension, dir) → (non-null) {Promise.<string>}

Installs an extension to the given directory.

Parameters:
NameTypeDescription
extensionstring

Path to the xpi extension file to install.

dirstring

Path to the directory to install the extension in.

Returns:

A promise for the add-on ID once installed.

Type: 
Promise.<string>