Selenium Firefox WebDriver implementation for automating Firefox browser interactions
—
Comprehensive configuration system for Firefox browser settings, preferences, command-line arguments, and capabilities. The FirefoxOptions class provides a fluent API for configuring all aspects of Firefox behavior.
Manages Firefox-specific settings and capabilities in a way that GeckoDriver can understand.
/**
* Manage Firefox specific settings in a way that geckodriver can understand.
* Extends AbstractDriverOptions to provide Firefox-specific configuration.
*/
public class FirefoxOptions extends AbstractDriverOptions<FirefoxOptions> {
/**
* Capability key for Firefox options in WebDriver capabilities map.
*/
public static final String FIREFOX_OPTIONS = "moz:firefoxOptions";
/**
* Creates a new FirefoxOptions instance with default settings.
* Sets browser name to "firefox" and enables BiDi protocol.
*/
public FirefoxOptions();
/**
* Creates FirefoxOptions from existing capabilities.
* @param source Capabilities to copy settings from
*/
public FirefoxOptions(Capabilities source);
}Usage Examples:
import org.openqa.selenium.firefox.FirefoxOptions;
// Basic options creation
FirefoxOptions options = new FirefoxOptions();
// Options from existing capabilities
Capabilities existingCaps = new ImmutableCapabilities("browserName", "firefox");
FirefoxOptions options = new FirefoxOptions(existingCaps);Configures options from system properties and environment variables.
/**
* Configures Firefox options from system properties and environment variables.
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions configureFromEnv();Usage Examples:
// Configure from environment automatically
FirefoxOptions options = new FirefoxOptions().configureFromEnv();
// Set system properties before configuration
System.setProperty("webdriver.firefox.bin", "/opt/firefox/firefox");
System.setProperty("webdriver.firefox.profile", "/tmp/firefox-profile");
FirefoxOptions options = new FirefoxOptions().configureFromEnv();Specifies the Firefox executable to use, supporting different Firefox installations.
/**
* Gets the Firefox binary configuration.
* @return FirefoxBinary instance
* @deprecated Use getBinaryOrNull() or system properties instead
*/
@Deprecated
public FirefoxBinary getBinary();
/**
* Gets the Firefox binary as Optional.
* @return Optional containing FirefoxBinary, empty if not set
* @deprecated Use system properties instead
*/
@Deprecated
public Optional<FirefoxBinary> getBinaryOrNull();
/**
* Sets the Firefox binary to use.
* @param binary FirefoxBinary instance
* @return This FirefoxOptions instance for method chaining
* @deprecated Use setBinary(Path) instead
*/
@Deprecated
public FirefoxOptions setBinary(FirefoxBinary binary);
/**
* Sets the Firefox executable path.
* @param path Path to Firefox executable
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setBinary(Path path);
/**
* Sets the Firefox executable path as string.
* @param path String path to Firefox executable
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setBinary(String path);Usage Examples:
import java.nio.file.Paths;
FirefoxOptions options = new FirefoxOptions()
.setBinary("/usr/bin/firefox")
.setBinary(Paths.get("/Applications/Firefox.app/Contents/MacOS/firefox"));Sets the Firefox user profile for customization and data persistence.
/**
* Gets the current Firefox profile.
* @return FirefoxProfile instance, null if not set
*/
public FirefoxProfile getProfile();
/**
* Sets the Firefox profile to use.
* @param profile FirefoxProfile instance with custom settings
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setProfile(FirefoxProfile profile);Adds command-line arguments passed to the Firefox process.
/**
* Adds command-line arguments to Firefox process.
* @param arguments Variable number of argument strings
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions addArguments(String... arguments);
/**
* Adds command-line arguments from a list.
* @param arguments List of argument strings
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions addArguments(List<String> arguments);Usage Examples:
FirefoxOptions options = new FirefoxOptions()
.addArguments("--headless")
.addArguments("--width=1920", "--height=1080")
.addArguments(Arrays.asList("--disable-extensions", "--no-sandbox"));Sets Firefox about:config preferences for detailed browser behavior control.
/**
* Sets a Firefox preference value.
* @param key Preference name (about:config key)
* @param value Preference value (String, Integer, Boolean)
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions addPreference(String key, Object value);Usage Examples:
FirefoxOptions options = new FirefoxOptions()
.addPreference("browser.startup.page", 1)
.addPreference("browser.startup.homepage", "https://example.com")
.addPreference("dom.webnotifications.enabled", false)
.addPreference("browser.download.folderList", 2)
.addPreference("browser.download.dir", "/path/to/downloads");Configures GeckoDriver logging level for debugging and troubleshooting.
/**
* Sets the GeckoDriver log level.
* @param logLevel Log level from FirefoxDriverLogLevel enum
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setLogLevel(FirefoxDriverLogLevel logLevel);Configures Firefox for Android automation when using mobile testing.
/**
* Sets the Android package name for Firefox Android automation.
* @param androidPackage Package name (e.g., "org.mozilla.firefox")
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setAndroidPackage(String androidPackage);
/**
* Sets the Android activity for Firefox Android automation.
* @param activity Activity name to start
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setAndroidActivity(String activity);
/**
* Sets the Android device serial number for targeting specific devices.
* @param serial Device serial number
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setAndroidDeviceSerialNumber(String serial);
/**
* Sets Android intent arguments as array.
* @param args Intent argument array
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setAndroidIntentArguments(String[] args);
/**
* Sets Android intent arguments as list.
* @param args Intent argument list
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions setAndroidIntentArguments(List<String> args);Usage Examples:
FirefoxOptions options = new FirefoxOptions()
.setAndroidPackage("org.mozilla.firefox")
.setAndroidActivity("org.mozilla.gecko.BrowserApp")
.setAndroidDeviceSerialNumber("emulator-5554")
.setAndroidIntentArguments(new String[]{"--verbose", "--debug"});Enables modern WebDriver BiDi protocol support for advanced automation features.
/**
* Enables WebDriver BiDi protocol support.
* Required for BiDi functionality access.
* @return This FirefoxOptions instance for method chaining
*/
public FirefoxOptions enableBiDi();Merges additional capabilities with Firefox-specific options.
/**
* Merges the provided capabilities with existing options.
* @param capabilities Additional capabilities to merge
* @return New FirefoxOptions instance with merged capabilities
*/
public FirefoxOptions merge(Capabilities capabilities);Complete Configuration Example:
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import java.nio.file.Paths;
// Create comprehensive Firefox configuration
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.cache.disk.enable", false);
profile.setPreference("browser.cache.memory.enable", false);
FirefoxOptions options = new FirefoxOptions()
// Binary configuration
.setBinary("/opt/firefox/firefox")
// Profile setup
.setProfile(profile)
// Command line arguments
.addArguments("--headless")
.addArguments("--width=1920", "--height=1080")
// Firefox preferences
.addPreference("browser.startup.page", 0)
.addPreference("browser.startup.homepage", "about:blank")
.addPreference("dom.webnotifications.enabled", false)
.addPreference("media.navigator.permission.disabled", true)
// Logging
.setLogLevel(FirefoxDriverLogLevel.INFO)
// BiDi support
.enableBiDi()
// Standard WebDriver capabilities
.setAcceptInsecureCerts(true)
.setPageLoadStrategy(PageLoadStrategy.NORMAL);
// Use with driver
WebDriver driver = new FirefoxDriver(options);Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-firefox-driver