0
# Driver Management
1
2
Core Firefox WebDriver functionality including driver instantiation, configuration, and lifecycle management. The FirefoxDriver class provides the main entry point for Firefox browser automation.
3
4
## Capabilities
5
6
### FirefoxDriver Class
7
8
Main WebDriver implementation for Firefox browser automation, extending RemoteWebDriver with Firefox-specific capabilities.
9
10
```java { .api }
11
/**
12
* An implementation of the WebDriver interface that drives Firefox.
13
* Extends RemoteWebDriver and implements multiple Firefox-specific interfaces.
14
*/
15
public class FirefoxDriver extends RemoteWebDriver
16
implements WebStorage, HasExtensions, HasFullPageScreenshot, HasContext, HasBiDi {
17
18
/**
19
* Creates a new FirefoxDriver using the default GeckoDriverService configuration.
20
*/
21
public FirefoxDriver();
22
23
/**
24
* Creates a new FirefoxDriver instance with the specified options.
25
* @param options The FirefoxOptions to use for configuration
26
*/
27
public FirefoxDriver(FirefoxOptions options);
28
29
/**
30
* Creates a new FirefoxDriver instance with custom service.
31
* @param service The FirefoxDriverService to use
32
*/
33
public FirefoxDriver(FirefoxDriverService service);
34
35
/**
36
* Creates a new FirefoxDriver instance with service and options.
37
* @param service The FirefoxDriverService to use
38
* @param options The FirefoxOptions to use for configuration
39
*/
40
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options);
41
42
/**
43
* Creates a new FirefoxDriver instance with full configuration.
44
* @param service The FirefoxDriverService to use
45
* @param options The FirefoxOptions to use for configuration
46
* @param clientConfig HTTP client configuration
47
*/
48
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, ClientConfig clientConfig);
49
}
50
```
51
52
**Usage Examples:**
53
54
```java
55
import org.openqa.selenium.firefox.FirefoxDriver;
56
import org.openqa.selenium.firefox.FirefoxOptions;
57
import org.openqa.selenium.firefox.GeckoDriverService;
58
import org.openqa.selenium.WebDriver;
59
60
// Simple driver creation
61
WebDriver driver = new FirefoxDriver();
62
63
// Driver with options
64
FirefoxOptions options = new FirefoxOptions()
65
.setHeadless(true)
66
.addPreference("browser.download.folderList", 2);
67
WebDriver driver = new FirefoxDriver(options);
68
69
// Driver with custom service
70
GeckoDriverService service = new GeckoDriverService.Builder()
71
.withLogLevel(FirefoxDriverLogLevel.DEBUG)
72
.build();
73
WebDriver driver = new FirefoxDriver(service, options);
74
```
75
76
### Builder Pattern
77
78
Static factory method for creating FirefoxDriver instances using builder pattern.
79
80
```java { .api }
81
/**
82
* Returns a builder for creating FirefoxDriver instances.
83
* @return RemoteWebDriverBuilder configured for Firefox
84
*/
85
@Beta
86
public static RemoteWebDriverBuilder builder();
87
```
88
89
### Core WebDriver Methods
90
91
Standard WebDriver interface methods with Firefox-specific implementations.
92
93
```java { .api }
94
/**
95
* Gets the current browser capabilities.
96
* @return Capabilities object representing current browser state
97
*/
98
public Capabilities getCapabilities();
99
100
/**
101
* Sets the file detector for handling file uploads.
102
* @param detector FileDetector implementation
103
* @throws WebDriverException if detector cannot be set
104
*/
105
public void setFileDetector(FileDetector detector) throws WebDriverException;
106
107
/**
108
* Quits the driver and closes all associated windows.
109
*/
110
public void quit();
111
```
112
113
### Legacy WebStorage Support
114
115
Deprecated HTML5 storage interfaces provided for backward compatibility.
116
117
```java { .api }
118
/**
119
* Gets the local storage interface.
120
* @return LocalStorage interface
121
* @deprecated Use JavaScript execution instead
122
*/
123
@Deprecated
124
public LocalStorage getLocalStorage();
125
126
/**
127
* Gets the session storage interface.
128
* @return SessionStorage interface
129
* @deprecated Use JavaScript execution instead
130
*/
131
@Deprecated
132
public SessionStorage getSessionStorage();
133
```
134
135
### System Properties
136
137
Constants for configuring Firefox driver through system properties.
138
139
```java { .api }
140
public static class SystemProperty {
141
/**
142
* System property for specifying Firefox executable path.
143
* Property name: "webdriver.firefox.bin"
144
*/
145
public static final String BROWSER_BINARY = "webdriver.firefox.bin";
146
147
/**
148
* System property for specifying Firefox profile path.
149
* Property name: "webdriver.firefox.profile"
150
*/
151
public static final String BROWSER_PROFILE = "webdriver.firefox.profile";
152
}
153
```
154
155
### Extension Management Interface
156
157
Firefox-specific extension management capabilities implemented by FirefoxDriver.
158
159
```java { .api }
160
/**
161
* Installs a browser extension from a file path.
162
* @param path Path to extension file (.xpi) or directory
163
* @return Extension ID string for later reference
164
*/
165
public String installExtension(Path path);
166
167
/**
168
* Installs a browser extension with temporary flag option.
169
* @param path Path to extension file (.xpi) or directory
170
* @param temporary true for temporary installation, false for permanent
171
* @return Extension ID string for later reference
172
*/
173
public String installExtension(Path path, Boolean temporary);
174
175
/**
176
* Uninstalls a previously installed extension.
177
* @param extensionId Extension ID returned from installExtension
178
*/
179
public void uninstallExtension(String extensionId);
180
```
181
182
### Full Page Screenshot Interface
183
184
Enhanced screenshot capabilities for capturing complete page content.
185
186
```java { .api }
187
/**
188
* Takes a full-page screenshot of the current page.
189
* Captures the entire page content, not just the visible viewport.
190
* @param outputType Output format for the screenshot (FILE, BYTES, BASE64)
191
* @param <X> Return type determined by OutputType
192
* @return Screenshot in the specified format
193
*/
194
public <X> X getFullPageScreenshotAs(OutputType<X> outputType);
195
```
196
197
### Context Management Interface
198
199
Firefox-specific context switching between content and chrome contexts.
200
201
```java { .api }
202
/**
203
* Gets the current command execution context.
204
* @return Current FirefoxCommandContext (CONTENT or CHROME)
205
*/
206
public FirefoxCommandContext getContext();
207
208
/**
209
* Sets the current command execution context.
210
* @param context FirefoxCommandContext specifying the target context
211
*/
212
public void setContext(FirefoxCommandContext context);
213
```
214
215
**Usage Examples:**
216
217
```java
218
// Set system properties before driver creation
219
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_BINARY, "/path/to/firefox");
220
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_PROFILE, "/path/to/profile");
221
222
WebDriver driver = new FirefoxDriver();
223
```
224
225
### BiDi Protocol Support
226
227
Modern WebDriver BiDi protocol access for advanced browser automation.
228
229
```java { .api }
230
/**
231
* Returns BiDi connection if available.
232
* @return Optional containing BiDi instance, empty if not available
233
*/
234
public Optional<BiDi> maybeGetBiDi();
235
236
/**
237
* Returns BiDi connection, throwing exception if unavailable.
238
* @return BiDi instance for WebDriver BiDi operations
239
* @throws BiDiException if BiDi is not available or enabled
240
*/
241
public BiDi getBiDi() throws BiDiException;
242
```
243
244
**Usage Examples:**
245
246
```java
247
FirefoxOptions options = new FirefoxOptions().enableBiDi();
248
FirefoxDriver driver = new FirefoxDriver(options);
249
250
// Check for BiDi availability
251
Optional<BiDi> biDi = driver.maybeGetBiDi();
252
if (biDi.isPresent()) {
253
// Use BiDi functionality
254
BiDi biDiConnection = biDi.get();
255
// ... BiDi operations
256
}
257
258
// Or get BiDi directly (throws if unavailable)
259
try {
260
BiDi biDiConnection = driver.getBiDi();
261
// ... BiDi operations
262
} catch (BiDiException e) {
263
// Handle BiDi unavailability
264
}
265
```