0
# Edge Options
1
2
EdgeOptions provides configuration and capability management for EdgeDriver with Edge-specific options, WebView2 support, and comprehensive browser customization capabilities inherited from ChromiumOptions.
3
4
## Capabilities
5
6
### EdgeOptions Class
7
8
Configuration class for EdgeDriver-specific browser options and capabilities.
9
10
```java { .api }
11
/**
12
* Class to manage options specific to EdgeDriver.
13
*/
14
public class EdgeOptions extends ChromiumOptions<EdgeOptions> {
15
/** Key used to store EdgeOptions in a Capabilities object */
16
public static final String CAPABILITY = "ms:edgeOptions";
17
18
/** Key for Edge logging preferences */
19
public static final String LOGGING_PREFS = "ms:loggingPrefs";
20
21
/** Browser name for WebView2 automation */
22
public static final String WEBVIEW2_BROWSER_NAME = "webview2";
23
24
/**
25
* Creates default EdgeOptions with Edge browser name
26
*/
27
public EdgeOptions();
28
29
/**
30
* Enables or disables WebView2 automation mode
31
* @param enable true to enable WebView2 mode, false for regular Edge
32
* @return this EdgeOptions instance for method chaining
33
*/
34
public EdgeOptions useWebView(boolean enable);
35
36
/**
37
* Merges additional capabilities with these options
38
* @param extraCapabilities Capabilities to merge
39
* @return new EdgeOptions instance with merged capabilities
40
*/
41
public EdgeOptions merge(Capabilities extraCapabilities);
42
}
43
```
44
45
**Usage Examples:**
46
47
```java
48
import org.openqa.selenium.edge.EdgeOptions;
49
import org.openqa.selenium.PageLoadStrategy;
50
51
// Basic options
52
EdgeOptions options = new EdgeOptions();
53
54
// WebView2 mode
55
EdgeOptions webViewOptions = new EdgeOptions();
56
webViewOptions.useWebView(true);
57
58
// Merge capabilities
59
EdgeOptions baseOptions = new EdgeOptions();
60
EdgeOptions merged = baseOptions.merge(new ImmutableCapabilities(
61
CapabilityType.PAGE_LOAD_STRATEGY, PageLoadStrategy.NONE
62
));
63
```
64
65
### Binary Configuration
66
67
Set the path to the Edge executable for custom installations.
68
69
```java { .api }
70
/**
71
* Sets the path to the Edge executable
72
* @param path File path to Edge executable
73
* @return this EdgeOptions instance for method chaining
74
*/
75
public EdgeOptions setBinary(File path);
76
77
/**
78
* Sets the path to the Edge executable
79
* @param path String path to Edge executable
80
* @return this EdgeOptions instance for method chaining
81
*/
82
public EdgeOptions setBinary(String path);
83
```
84
85
**Usage Examples:**
86
87
```java
88
EdgeOptions options = new EdgeOptions();
89
options.setBinary("/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge");
90
91
// Or with File object
92
options.setBinary(new File("/path/to/msedge"));
93
```
94
95
### Command Line Arguments
96
97
Add command line arguments to customize Edge browser behavior.
98
99
```java { .api }
100
/**
101
* Adds command line arguments to pass to Edge
102
* @param arguments Variable number of string arguments
103
* @return this EdgeOptions instance for method chaining
104
*/
105
public EdgeOptions addArguments(String... arguments);
106
107
/**
108
* Adds command line arguments from a list
109
* @param arguments List of string arguments
110
* @return this EdgeOptions instance for method chaining
111
*/
112
public EdgeOptions addArguments(List<String> arguments);
113
```
114
115
**Usage Examples:**
116
117
```java
118
EdgeOptions options = new EdgeOptions();
119
options.addArguments("--headless");
120
options.addArguments("--disable-gpu");
121
options.addArguments("--window-size=1920,1080");
122
123
// Multiple arguments at once
124
options.addArguments("--no-sandbox", "--disable-dev-shm-usage");
125
126
// From list
127
List<String> args = Arrays.asList("--incognito", "--disable-extensions");
128
options.addArguments(args);
129
```
130
131
### Extensions
132
133
Add browser extensions to the Edge instance.
134
135
```java { .api }
136
/**
137
* Adds extension files to be loaded in Edge
138
* @param paths Variable number of File objects pointing to .crx files
139
* @return this EdgeOptions instance for method chaining
140
*/
141
public EdgeOptions addExtensions(File... paths);
142
143
/**
144
* Adds base64-encoded extensions to be loaded in Edge
145
* @param encoded Variable number of base64-encoded extension strings
146
* @return this EdgeOptions instance for method chaining
147
*/
148
public EdgeOptions addEncodedExtensions(String... encoded);
149
```
150
151
**Usage Examples:**
152
153
```java
154
EdgeOptions options = new EdgeOptions();
155
156
// Add extension files
157
options.addExtensions(new File("/path/to/extension.crx"));
158
options.addExtensions(
159
new File("/path/to/ext1.crx"),
160
new File("/path/to/ext2.crx")
161
);
162
163
// Add base64-encoded extensions
164
String encodedExt = Base64.getEncoder().encodeToString(extensionBytes);
165
options.addEncodedExtensions(encodedExt);
166
```
167
168
### Experimental Options
169
170
Set experimental options for Edge browser features.
171
172
```java { .api }
173
/**
174
* Sets an experimental option for Edge
175
* @param name Name of the experimental option
176
* @param value Value for the experimental option
177
* @return this EdgeOptions instance for method chaining
178
*/
179
public EdgeOptions setExperimentalOption(String name, Object value);
180
```
181
182
**Usage Examples:**
183
184
```java
185
EdgeOptions options = new EdgeOptions();
186
187
// Enable performance logging
188
options.setExperimentalOption("perfLoggingPrefs", Map.of(
189
"enableNetwork", true,
190
"enablePage", true
191
));
192
193
// Custom download directory
194
options.setExperimentalOption("prefs", Map.of(
195
"download.default_directory", "/custom/download/path"
196
));
197
198
// Device emulation
199
options.setExperimentalOption("mobileEmulation", Map.of(
200
"deviceName", "iPhone 12"
201
));
202
```
203
204
### Standard Browser Options
205
206
Configure standard browser behavior options.
207
208
```java { .api }
209
/**
210
* Enables or disables headless mode
211
* @param headless true for headless mode, false for headed mode
212
* @return this EdgeOptions instance for method chaining
213
*/
214
public EdgeOptions setHeadless(boolean headless);
215
216
/**
217
* Sets whether to accept insecure certificates
218
* @param accept true to accept insecure certificates
219
* @return this EdgeOptions instance for method chaining
220
*/
221
public EdgeOptions setAcceptInsecureCerts(boolean accept);
222
223
/**
224
* Sets the page load strategy
225
* @param strategy PageLoadStrategy (NORMAL, EAGER, NONE)
226
* @return this EdgeOptions instance for method chaining
227
*/
228
public EdgeOptions setPageLoadStrategy(PageLoadStrategy strategy);
229
230
/**
231
* Sets unhandled prompt behavior
232
* @param behaviour UnexpectedAlertBehaviour for handling prompts
233
* @return this EdgeOptions instance for method chaining
234
*/
235
public EdgeOptions setUnhandledPromptBehaviour(UnexpectedAlertBehaviour behaviour);
236
237
/**
238
* Sets target platform
239
* @param platform Platform specification
240
* @return this EdgeOptions instance for method chaining
241
*/
242
public EdgeOptions setPlatformName(Platform platform);
243
```
244
245
**Usage Examples:**
246
247
```java
248
EdgeOptions options = new EdgeOptions();
249
250
options.setHeadless(true);
251
options.setAcceptInsecureCerts(true);
252
options.setPageLoadStrategy(PageLoadStrategy.EAGER);
253
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS);
254
options.setPlatformName(Platform.WINDOWS);
255
```
256
257
### Capability Management
258
259
Set and retrieve arbitrary capabilities.
260
261
```java { .api }
262
/**
263
* Sets a capability value
264
* @param key Capability name
265
* @param value Capability value
266
* @return this EdgeOptions instance for method chaining
267
*/
268
public EdgeOptions setCapability(String key, Object value);
269
270
/**
271
* Gets a capability value
272
* @param capabilityName Name of the capability
273
* @return Capability value or null if not set
274
*/
275
public Object getCapability(String capabilityName);
276
277
/**
278
* Gets browser name capability
279
* @return Browser name ("MicrosoftEdge" or "webview2")
280
*/
281
public String getBrowserName();
282
283
/**
284
* Converts options to a capabilities map
285
* @return Map of capability names to values
286
*/
287
public Map<String, Object> asMap();
288
```
289
290
**Usage Examples:**
291
292
```java
293
EdgeOptions options = new EdgeOptions();
294
295
// Set custom capabilities
296
options.setCapability("customCapability", "customValue");
297
options.setCapability("timeouts", Map.of(
298
"implicit", 10000,
299
"pageLoad", 30000
300
));
301
302
// Get capabilities
303
String browserName = options.getBrowserName();
304
Object timeout = options.getCapability("timeouts");
305
306
// Convert to map for inspection
307
Map<String, Object> caps = options.asMap();
308
```
309
310
### WebView2 Configuration
311
312
Configure Edge for WebView2 application automation.
313
314
```java { .api }
315
/**
316
* Changes browser name to 'webview2' to enable WebView2 app automation
317
* @param enable true to enable WebView2 mode, false for regular Edge
318
* @return this EdgeOptions instance for method chaining
319
*/
320
public EdgeOptions useWebView(boolean enable);
321
```
322
323
**Usage Examples:**
324
325
```java
326
EdgeOptions options = new EdgeOptions();
327
328
// Enable WebView2 mode
329
options.useWebView(true);
330
String browserName = options.getBrowserName(); // Returns "webview2"
331
332
// Disable WebView2 mode
333
options.useWebView(false);
334
browserName = options.getBrowserName(); // Returns "MicrosoftEdge"
335
336
// Use with EdgeDriver
337
EdgeDriver driver = new EdgeDriver(options);
338
driver.get("webview2://embedded-app");
339
```
340
341
## Types
342
343
```java { .api }
344
import org.openqa.selenium.Capabilities;
345
import org.openqa.selenium.ImmutableCapabilities;
346
import org.openqa.selenium.PageLoadStrategy;
347
import org.openqa.selenium.Platform;
348
import org.openqa.selenium.UnexpectedAlertBehaviour;
349
import org.openqa.selenium.chromium.ChromiumOptions;
350
import org.openqa.selenium.remote.CapabilityType;
351
352
// Enums
353
enum PageLoadStrategy {
354
NORMAL, EAGER, NONE
355
}
356
357
enum UnexpectedAlertBehaviour {
358
DISMISS, ACCEPT, DISMISS_AND_NOTIFY, ACCEPT_AND_NOTIFY, IGNORE
359
}
360
361
enum Platform {
362
WINDOWS, MAC, LINUX, UNIX, VISTA, WIN8, WIN8_1, WIN10, XP, ANDROID, IOS, MAVERICKS, YOSEMITE, EL_CAPITAN, SIERRA, HIGH_SIERRA, MOJAVE, CATALINA, BIG_SUR, MONTEREY, VENTURA, ANY
363
}
364
```