Selenium Firefox WebDriver implementation for automating Firefox browser interactions
—
Core Firefox WebDriver functionality including driver instantiation, configuration, and lifecycle management. The FirefoxDriver class provides the main entry point for Firefox browser automation.
Main WebDriver implementation for Firefox browser automation, extending RemoteWebDriver with Firefox-specific capabilities.
/**
* An implementation of the WebDriver interface that drives Firefox.
* Extends RemoteWebDriver and implements multiple Firefox-specific interfaces.
*/
public class FirefoxDriver extends RemoteWebDriver
implements WebStorage, HasExtensions, HasFullPageScreenshot, HasContext, HasBiDi {
/**
* Creates a new FirefoxDriver using the default GeckoDriverService configuration.
*/
public FirefoxDriver();
/**
* Creates a new FirefoxDriver instance with the specified options.
* @param options The FirefoxOptions to use for configuration
*/
public FirefoxDriver(FirefoxOptions options);
/**
* Creates a new FirefoxDriver instance with custom service.
* @param service The FirefoxDriverService to use
*/
public FirefoxDriver(FirefoxDriverService service);
/**
* Creates a new FirefoxDriver instance with service and options.
* @param service The FirefoxDriverService to use
* @param options The FirefoxOptions to use for configuration
*/
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options);
/**
* Creates a new FirefoxDriver instance with full configuration.
* @param service The FirefoxDriverService to use
* @param options The FirefoxOptions to use for configuration
* @param clientConfig HTTP client configuration
*/
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, ClientConfig clientConfig);
}Usage Examples:
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.GeckoDriverService;
import org.openqa.selenium.WebDriver;
// Simple driver creation
WebDriver driver = new FirefoxDriver();
// Driver with options
FirefoxOptions options = new FirefoxOptions()
.setHeadless(true)
.addPreference("browser.download.folderList", 2);
WebDriver driver = new FirefoxDriver(options);
// Driver with custom service
GeckoDriverService service = new GeckoDriverService.Builder()
.withLogLevel(FirefoxDriverLogLevel.DEBUG)
.build();
WebDriver driver = new FirefoxDriver(service, options);Static factory method for creating FirefoxDriver instances using builder pattern.
/**
* Returns a builder for creating FirefoxDriver instances.
* @return RemoteWebDriverBuilder configured for Firefox
*/
@Beta
public static RemoteWebDriverBuilder builder();Standard WebDriver interface methods with Firefox-specific implementations.
/**
* Gets the current browser capabilities.
* @return Capabilities object representing current browser state
*/
public Capabilities getCapabilities();
/**
* Sets the file detector for handling file uploads.
* @param detector FileDetector implementation
* @throws WebDriverException if detector cannot be set
*/
public void setFileDetector(FileDetector detector) throws WebDriverException;
/**
* Quits the driver and closes all associated windows.
*/
public void quit();Deprecated HTML5 storage interfaces provided for backward compatibility.
/**
* Gets the local storage interface.
* @return LocalStorage interface
* @deprecated Use JavaScript execution instead
*/
@Deprecated
public LocalStorage getLocalStorage();
/**
* Gets the session storage interface.
* @return SessionStorage interface
* @deprecated Use JavaScript execution instead
*/
@Deprecated
public SessionStorage getSessionStorage();Constants for configuring Firefox driver through system properties.
public static class SystemProperty {
/**
* System property for specifying Firefox executable path.
* Property name: "webdriver.firefox.bin"
*/
public static final String BROWSER_BINARY = "webdriver.firefox.bin";
/**
* System property for specifying Firefox profile path.
* Property name: "webdriver.firefox.profile"
*/
public static final String BROWSER_PROFILE = "webdriver.firefox.profile";
}Firefox-specific extension management capabilities implemented by FirefoxDriver.
/**
* Installs a browser extension from a file path.
* @param path Path to extension file (.xpi) or directory
* @return Extension ID string for later reference
*/
public String installExtension(Path path);
/**
* Installs a browser extension with temporary flag option.
* @param path Path to extension file (.xpi) or directory
* @param temporary true for temporary installation, false for permanent
* @return Extension ID string for later reference
*/
public String installExtension(Path path, Boolean temporary);
/**
* Uninstalls a previously installed extension.
* @param extensionId Extension ID returned from installExtension
*/
public void uninstallExtension(String extensionId);Enhanced screenshot capabilities for capturing complete page content.
/**
* Takes a full-page screenshot of the current page.
* Captures the entire page content, not just the visible viewport.
* @param outputType Output format for the screenshot (FILE, BYTES, BASE64)
* @param <X> Return type determined by OutputType
* @return Screenshot in the specified format
*/
public <X> X getFullPageScreenshotAs(OutputType<X> outputType);Firefox-specific context switching between content and chrome contexts.
/**
* Gets the current command execution context.
* @return Current FirefoxCommandContext (CONTENT or CHROME)
*/
public FirefoxCommandContext getContext();
/**
* Sets the current command execution context.
* @param context FirefoxCommandContext specifying the target context
*/
public void setContext(FirefoxCommandContext context);Usage Examples:
// Set system properties before driver creation
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_BINARY, "/path/to/firefox");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_PROFILE, "/path/to/profile");
WebDriver driver = new FirefoxDriver();Modern WebDriver BiDi protocol access for advanced browser automation.
/**
* Returns BiDi connection if available.
* @return Optional containing BiDi instance, empty if not available
*/
public Optional<BiDi> maybeGetBiDi();
/**
* Returns BiDi connection, throwing exception if unavailable.
* @return BiDi instance for WebDriver BiDi operations
* @throws BiDiException if BiDi is not available or enabled
*/
public BiDi getBiDi() throws BiDiException;Usage Examples:
FirefoxOptions options = new FirefoxOptions().enableBiDi();
FirefoxDriver driver = new FirefoxDriver(options);
// Check for BiDi availability
Optional<BiDi> biDi = driver.maybeGetBiDi();
if (biDi.isPresent()) {
// Use BiDi functionality
BiDi biDiConnection = biDi.get();
// ... BiDi operations
}
// Or get BiDi directly (throws if unavailable)
try {
BiDi biDiConnection = driver.getBiDi();
// ... BiDi operations
} catch (BiDiException e) {
// Handle BiDi unavailability
}Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-firefox-driver