Table of Contents

Class FirefoxDriver

Namespace
OpenQA.Selenium.Firefox
Assembly
WebDriver.dll

Provides a way to access Firefox to run tests.

public class FirefoxDriver : WebDriver, IWebDriver, IDisposable, ISearchContext, IJavaScriptExecutor, IFindsElement, ITakesScreenshot, ISupportsPrint, IActionExecutor, IAllowsFileDetection, IHasCapabilities, IHasCommandExecutor, IHasSessionId, ICustomDriverCommandExecutor, IHasVirtualAuthenticator, IDevTools
Inheritance
FirefoxDriver
Implements
Inherited Members
Extension Methods

Examples

[TestFixture]
public class Testing
{
    private IWebDriver driver;

    [SetUp]
    public void SetUp()
    {
        driver = new FirefoxDriver();
    }

    [Test]
    public void TestGoogle()
    {
        driver.Navigate().GoToUrl("http://www.google.co.uk");
        /*
        *   Rest of the test
        */
    }

    [TearDown]
    public void TearDown()
    {
        driver.Quit();
    }
}

Remarks

When the FirefoxDriver object has been instantiated the browser will load. The test can then navigate to the URL under test and start your test.

In the case of the FirefoxDriver, you can specify a named profile to be used, or you can let the driver create a temporary, anonymous profile. A custom extension allowing the driver to communicate to the browser will be installed into the profile.

Constructors

FirefoxDriver()

Initializes a new instance of the FirefoxDriver class.

public FirefoxDriver()

FirefoxDriver(FirefoxDriverService)

Initializes a new instance of the FirefoxDriver class using the specified driver service. Uses the Mozilla-provided Marionette driver implementation.

public FirefoxDriver(FirefoxDriverService service)

Parameters

service FirefoxDriverService

The FirefoxDriverService used to initialize the driver.

FirefoxDriver(FirefoxDriverService, FirefoxOptions)

Initializes a new instance of the FirefoxDriver class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.

public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options)

Parameters

service FirefoxDriverService

The FirefoxDriverService to use.

options FirefoxOptions

The FirefoxOptions to be used with the Firefox driver.

FirefoxDriver(FirefoxDriverService, FirefoxOptions, TimeSpan)

Initializes a new instance of the FirefoxDriver class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.

public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)

Parameters

service FirefoxDriverService

The FirefoxDriverService to use.

options FirefoxOptions

The FirefoxOptions to be used with the Firefox driver.

commandTimeout TimeSpan

The maximum amount of time to wait for each command.

FirefoxDriver(FirefoxOptions)

Initializes a new instance of the FirefoxDriver class using the specified options. Uses the Mozilla-provided Marionette driver implementation.

public FirefoxDriver(FirefoxOptions options)

Parameters

options FirefoxOptions

The FirefoxOptions to be used with the Firefox driver.

FirefoxDriver(string)

Initializes a new instance of the FirefoxDriver class using the specified path to the directory containing geckodriver.exe.

public FirefoxDriver(string geckoDriverDirectory)

Parameters

geckoDriverDirectory string

The full path to the directory containing geckodriver.exe.

FirefoxDriver(string, FirefoxOptions)

Initializes a new instance of the FirefoxDriver class using the specified path to the directory containing geckodriver.exe and options.

public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options)

Parameters

geckoDriverDirectory string

The full path to the directory containing geckodriver.exe.

options FirefoxOptions

The FirefoxOptions to be used with the Firefox driver.

FirefoxDriver(string, FirefoxOptions, TimeSpan)

Initializes a new instance of the FirefoxDriver class using the specified path to the directory containing geckodriver.exe, options, and command timeout.

public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout)

Parameters

geckoDriverDirectory string

The full path to the directory containing geckodriver.exe.

options FirefoxOptions

The FirefoxOptions to be used with the Firefox driver.

commandTimeout TimeSpan

The maximum amount of time to wait for each command.

Fields

GetContextCommand

Command for getting the command context of a Firefox driver.

public static readonly string GetContextCommand

Field Value

string

GetFullPageScreenshotCommand

Command for getting aa full page screenshot from a Firefox driver.

public static readonly string GetFullPageScreenshotCommand

Field Value

string

InstallAddOnCommand

Command for installing an addon to a Firefox driver.

public static readonly string InstallAddOnCommand

Field Value

string

SetContextCommand

Command for setting the command context of a Firefox driver.

public static readonly string SetContextCommand

Field Value

string

UninstallAddOnCommand

Command for uninstalling an addon from a Firefox driver.

public static readonly string UninstallAddOnCommand

Field Value

string

Properties

CustomCommandDefinitions

Gets a read-only dictionary of the custom WebDriver commands defined for FirefoxDriver. The keys of the dictionary are the names assigned to the command; the values are the CommandInfo objects describing the command behavior.

public static IReadOnlyDictionary<string, CommandInfo> CustomCommandDefinitions { get; }

Property Value

IReadOnlyDictionary<string, CommandInfo>

FileDetector

Gets or sets the IFileDetector responsible for detecting sequences of keystrokes representing file paths and names.

public override IFileDetector FileDetector { get; set; }

Property Value

IFileDetector

Remarks

The Firefox driver does not allow a file detector to be set, as the server component of the Firefox driver only allows uploads from the local computer environment. Attempting to set this property has no effect, but does not throw an exception. If you are attempting to run the Firefox driver remotely, use RemoteWebDriver in conjunction with a standalone WebDriver server.

HasActiveDevToolsSession

Gets a value indicating whether a DevTools session is active.

public bool HasActiveDevToolsSession { get; }

Property Value

bool

Methods

CloseDevToolsSession()

Closes a DevTools session.

public void CloseDevToolsSession()

Dispose(bool)

Disposes of the FirefoxDriver and frees all resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

A value indicating whether the user initiated the disposal of the object. Pass true if the user is actively disposing the object; otherwise false.

GetContext()

Sets the command context used when issuing commands to geckodriver.

public FirefoxCommandContext GetContext()

Returns

FirefoxCommandContext

The context of commands.

Exceptions

WebDriverException

If response is not recognized

GetDevToolsSession()

Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.

[Obsolete("CDP support for Firefox is deprecated and will be removed in future versions. Please switch to WebDriver BiDi.")]
public DevToolsSession GetDevToolsSession()

Returns

DevToolsSession

The active session to use to communicate with the Chromium Developer Tools debugging protocol.

GetDevToolsSession(DevToolsOptions)

Creates a session to communicate with a browser using a Developer Tools debugging protocol.

[Obsolete("CDP support for Firefox is deprecated and will be removed in future versions. Please switch to WebDriver BiDi.")]
public DevToolsSession GetDevToolsSession(DevToolsOptions options)

Parameters

options DevToolsOptions

Returns

DevToolsSession

The active session to use to communicate with the Developer Tools debugging protocol.

GetDevToolsSession(int)

Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.

[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion)

Parameters

devToolsProtocolVersion int

The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version.

Returns

DevToolsSession

The active session to use to communicate with the Chromium Developer Tools debugging protocol.

GetFullPageScreenshot()

Gets a Screenshot object representing the image of the full page on the screen.

public Screenshot GetFullPageScreenshot()

Returns

Screenshot

A Screenshot object containing the image.

InstallAddOn(string, bool)

Installs a Firefox add-on.

public string InstallAddOn(string base64EncodedAddOn, bool temporary = false)

Parameters

base64EncodedAddOn string

The base64-encoded string representation of the add-on binary.

temporary bool

Whether the add-on is temporary; required for unsigned add-ons.

Returns

string

The unique identifier of the installed add-on.

Exceptions

ArgumentNullException

If base64EncodedAddOn is null or empty.

InstallAddOnFromDirectory(string, bool)

Installs a Firefox add-on from a directory.

public string InstallAddOnFromDirectory(string addOnDirectoryToInstall, bool temporary = false)

Parameters

addOnDirectoryToInstall string

Full path of the directory of the add-on to install.

temporary bool

Whether the add-on is temporary; required for unsigned add-ons.

Returns

string

The unique identifier of the installed add-on.

Exceptions

ArgumentNullException

If addOnDirectoryToInstall is null or empty.

ArgumentException

If the directory at addOnDirectoryToInstall does not exist.

InstallAddOnFromFile(string, bool)

Installs a Firefox add-on from a file, typically a .xpi file.

public string InstallAddOnFromFile(string addOnFileToInstall, bool temporary = false)

Parameters

addOnFileToInstall string

Full path and file name of the add-on to install.

temporary bool

Whether the add-on is temporary; required for unsigned add-ons.

Returns

string

The unique identifier of the installed add-on.

Exceptions

ArgumentNullException

If addOnFileToInstall is null or empty.

or

If the file at addOnFileToInstall does not exist.

PrepareEnvironment()

In derived classes, the PrepareEnvironment() method prepares the environment for test execution.

protected virtual void PrepareEnvironment()

SetContext(FirefoxCommandContext)

Sets the command context used when issuing commands to geckodriver.

public void SetContext(FirefoxCommandContext context)

Parameters

context FirefoxCommandContext

The FirefoxCommandContext value to which to set the context.

UninstallAddOn(string)

Uninstalls a Firefox add-on.

public void UninstallAddOn(string addOnId)

Parameters

addOnId string

The ID of the add-on to uninstall.

Exceptions

ArgumentNullException

If addOnId is null or empty.