Skip to content

Latest commit

 

History

History
464 lines (405 loc) · 16.1 KB

File metadata and controls

464 lines (405 loc) · 16.1 KB
title linkTitle weight description aliases
Firefox specific functionality
Firefox
6
These are capabilities and features specific to Mozilla Firefox browsers.
/documentation/capabilities/firefox

Selenium 4 requires Firefox 78 or greater. It is recommended to always use the latest version of geckodriver.

Options

Capabilities common to all browsers are described on the [Options page]({{< ref "../drivers/options.md" >}}).

Capabilities unique to Firefox can be found at Mozilla's page for firefoxOptions

Starting a Firefox session with basic defined options looks like this:

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L36-L37" >}} {{< /tab >}} {{% tab header="Python" %}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L10-L11" >}} {{% /tab %}} {{< tab header="CSharp" >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs#L34-L35" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L10-L11" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/getting_started/openFirefoxTest.spec.js#L10-L13">}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Arguments

The args parameter is for a list of Command line switches used when starting the browser.
Commonly used args include -headless and "-profile", "/path/to/profile"

Add an argument to options:

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L44" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs#L43" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L17" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/firefoxSpecificFunctionalities.spec.js#L12">}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Start browser in a specified location

The binary parameter takes the path of an alternate location of browser to use. For example, with this parameter you can use geckodriver to drive Firefox Nightly instead of the production version when both are present on your computer.

Add a browser location to options:

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L54" >}} {{< /tab >}} {{% tab header="Python" %}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L28" >}} {{% /tab %}} {{< tab header="CSharp" >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs#L53" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L25" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Profiles

There are several ways to work with Firefox profiles.

{{< tabpane langEqualsHeader=true >}} {{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L211-L216" >}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L157-L165" >}} {{< /tab >}} {{< tab header="CSharp" >}} var options = new FirefoxOptions(); var profile = new FirefoxProfile(); options.Profile = profile; var driver = new FirefoxDriver(options); {{< /tab >}} {{< tab header="Ruby" text=true >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L139-L141" >}} {{< /tab >}} {{< tab header="JavaScript" >}} const { Builder } = require("selenium-webdriver"); const firefox = require('selenium-webdriver/firefox');

const options = new firefox.Options(); let profile = '/path to custom profile'; options.setProfile(profile); const driver = new Builder() .forBrowser('firefox') .setFirefoxOptions(options) .build(); {{< /tab >}} {{< tab header="Kotlin" >}} val options = FirefoxOptions() options.profile = FirefoxProfile() driver = FirefoxDriver(options) {{< /tab >}} {{< /tabpane >}} Note: Whether you create an empty FirefoxProfile or point it to the directory of your own profile, Selenium will create a temporary directory to store either the data of the new profile or a copy of your existing one. Every time you run your program, a different temporary directory will be created. These directories are not cleaned up explicitly by Selenium, they should eventually get removed by the operating system. However, if you want to remove the copy manually (e.g. if your profile is large in size), the path of the copy is exposed by the FirefoxProfile object. Check the language specific implementation to see how to retrieve that location.

If you want to use an existing Firefox profile, you can pass in the path to that profile. Please refer to the official Firefox documentation for instructions on how to find the directory of your profile.

Service

Service settings common to all browsers are described on the [Service page]({{< ref "../drivers/service.md" >}}).

Log output

Getting driver logs can be helpful for debugging various issues. The Service class lets you direct where the logs will go. Logging output is ignored unless the user directs it somewhere.

File output

To change the logging output to save to a specific file:

{{< tabpane text=true >}} {{% tab header="Java" %}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L62-L63" >}} Note: Java also allows setting file output by System Property:
Property key: GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY
Property value: String representing path to log file {{% /tab %}} {{< tab header="Python" >}} {{< badge-version version="4.11" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L36" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/ruby/spec/browsers/firefox_spec.rb#L43" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Console output

To change the logging output to display in the console:

{{< tabpane text=true >}} {{% tab header="Java" %}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L76-L77" >}} Note: Java also allows setting console output by System Property;
Property key: GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY
Property value: DriverService.LOG_STDOUT or DriverService.LOG_STDERR {{% /tab %}} {{< tab header="Python" >}} {{< badge-version version="4.11" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L48" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/ruby/spec/browsers/firefox_spec.rb#L52" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Log level

There are 7 available log levels: fatal, error, warn, info, config, debug, trace. If logging is specified the level defaults to info.

Note that -v is equivalent to -log debug and -vv is equivalent to log trace, so this examples is just for setting the log level generically:

{{< tabpane text=true >}} {{% tab header="Java" %}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L90-L91" >}} Note: Java also allows setting log level by System Property:
Property key: GeckoDriverService.GECKO_DRIVER_LOG_LEVEL_PROPERTY
Property value: String representation of FirefoxDriverLogLevel enum {{% /tab %}} {{< tab header="Python" >}} {{< badge-version version="4.11" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L59" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/ruby/spec/browsers/firefox_spec.rb#L63" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Truncated Logs

The driver logs everything that gets sent to it, including string representations of large binaries, so Firefox truncates lines by default. To turn off truncation:

{{< tabpane text=true >}} {{% tab header="Java" %}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L106-L107" >}} Note: Java also allows setting log level by System Property:
Property key: GeckoDriverService.GECKO_DRIVER_LOG_NO_TRUNCATE
Property value: "true" or "false" {{% /tab %}} {{< tab header="Python" >}} {{< badge-version version="4.11" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L70" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/ruby/spec/browsers/firefox_spec.rb#L72" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Profile Root

The default directory for profiles is the system temporary directory. If you do not have access to that directory, or want profiles to be created some place specific, you can change the profile root directory:

{{< tabpane text=true >}} {{% tab header="Java" %}} {{< badge-version version="4.10" >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L118-L119" >}} Note: Java also allows setting log level by System Property:
Property key: GeckoDriverService.GECKO_DRIVER_PROFILE_ROOT
Property value: String representing path to profile root directory {{% /tab %}} {{< tab header="Python" >}} {{< gh-codeblock path="examples/python/tests/browsers/test_firefox.py#L81" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-version version="4.8" >}} {{< gh-codeblock path="examples/ruby/spec/browsers/firefox_spec.rb#L81" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Special Features

Some browsers have implemented additional features that are unique to them.

Add-ons

Unlike Chrome, Firefox extensions are not added as part of capabilities as mentioned in this issue, they are created after starting the driver.

The following examples are for local webdrivers. For remote webdrivers, please refer to the [Remote WebDriver]({{< ref "../drivers/remote_webdriver" >}}) page.

Installation

A signed xpi file you would get from Mozilla Addon page

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L133" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L94" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs#L137" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L95" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/firefoxSpecificFunctionalities.spec.js#L25">}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Uninstallation

Uninstalling an addon requires knowing its id. The id can be obtained from the return value when installing the add-on.

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L148" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L106" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-version version="4.5" >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs#L152" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L106" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/firefoxSpecificFunctionalities.spec.js#L26">}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Unsigned installation

When working with an unfinished or unpublished extension, it will likely not be signed. As such, it can only be installed as "temporary." This can be done by passing in either a zip file or a directory, here's an example with a directory:

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L160" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L115" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-version version="4.5" >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs#L165" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-version version="4.5" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L115" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/firefoxSpecificFunctionalities.spec.js#L41">}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Full page screenshots

The following examples are for local webdrivers. For remote webdrivers, please refer to the [Remote WebDriver]({{< ref "../drivers/remote_webdriver" >}}) page.

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L181" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L139" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L125" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Context

The following examples are for local webdrivers. For remote webdrivers, please refer to the [Remote WebDriver]({{< ref "../drivers/remote_webdriver" >}}) page.

{{< tabpane text=true >}} {{< tab header="Java" >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java#L197-L198" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_firefox.py#L149-L150" >}} {{< /tab >}} {{< tab header="CSharp" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/browsers/firefox_spec.rb#L132" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-code >}} {{< /tab >}} {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} {{< /tabpane >}}

Note: As of Firefox 138, geckodriver needs to be started with the argument --allow-system-access to switch the context to CHROME.