0
# Edge Driver
1
2
EdgeDriver is the main WebDriver implementation for Microsoft Edge browser automation. It extends ChromiumDriver and provides all standard WebDriver functionality plus Edge-specific features like WebView2 support and Chrome DevTools Protocol integration.
3
4
## Capabilities
5
6
### EdgeDriver Class
7
8
Main WebDriver implementation for controlling Microsoft Edge browser instances.
9
10
```java { .api }
11
/**
12
* A WebDriver implementation that controls an Edge browser running on the local machine.
13
* Requires an edgedriver executable to be available in PATH.
14
*/
15
public class EdgeDriver extends ChromiumDriver {
16
/**
17
* Creates EdgeDriver with default EdgeOptions
18
*/
19
public EdgeDriver();
20
21
/**
22
* Creates EdgeDriver with specified options
23
* @param options EdgeOptions for browser configuration
24
*/
25
public EdgeDriver(EdgeOptions options);
26
27
/**
28
* Creates EdgeDriver with specified service and default options
29
* @param service EdgeDriverService for executable management
30
*/
31
public EdgeDriver(EdgeDriverService service);
32
33
/**
34
* Creates EdgeDriver with service and options
35
* @param service EdgeDriverService for executable management
36
* @param options EdgeOptions for browser configuration
37
*/
38
public EdgeDriver(EdgeDriverService service, EdgeOptions options);
39
40
/**
41
* Creates EdgeDriver with service, options, and client configuration
42
* @param service EdgeDriverService for executable management
43
* @param options EdgeOptions for browser configuration
44
* @param clientConfig ClientConfig for HTTP client settings
45
*/
46
public EdgeDriver(EdgeDriverService service, EdgeOptions options, ClientConfig clientConfig);
47
48
/**
49
* Creates RemoteWebDriverBuilder for Edge
50
* @return RemoteWebDriverBuilder configured for Edge
51
*/
52
@Beta
53
public static RemoteWebDriverBuilder builder();
54
}
55
```
56
57
**Usage Examples:**
58
59
```java
60
import org.openqa.selenium.edge.EdgeDriver;
61
import org.openqa.selenium.edge.EdgeOptions;
62
import org.openqa.selenium.edge.EdgeDriverService;
63
64
// Default configuration
65
EdgeDriver driver = new EdgeDriver();
66
67
// With custom options
68
EdgeOptions options = new EdgeOptions();
69
options.addArguments("--headless");
70
options.setBinary("/path/to/edge");
71
EdgeDriver driver = new EdgeDriver(options);
72
73
// With custom service
74
EdgeDriverService service = new EdgeDriverService.Builder()
75
.usingPort(9515)
76
.withVerbose(true)
77
.build();
78
EdgeDriver driver = new EdgeDriver(service);
79
80
// Full configuration
81
EdgeDriverService service = EdgeDriverService.createDefaultService();
82
EdgeOptions options = new EdgeOptions();
83
options.addArguments("--disable-extensions");
84
ClientConfig clientConfig = ClientConfig.defaultConfig();
85
EdgeDriver driver = new EdgeDriver(service, options, clientConfig);
86
```
87
88
### WebDriver API Methods
89
90
EdgeDriver inherits all standard WebDriver methods through ChromiumDriver:
91
92
```java { .api }
93
// Navigation
94
void get(String url);
95
String getCurrentUrl();
96
String getTitle();
97
String getPageSource();
98
void close();
99
void quit();
100
101
// Element finding
102
WebElement findElement(By by);
103
List<WebElement> findElements(By by);
104
105
// Window management
106
String getWindowHandle();
107
Set<String> getWindowHandles();
108
WebDriver.TargetLocator switchTo();
109
WebDriver.Navigation navigate();
110
WebDriver.Options manage();
111
112
// JavaScript execution
113
Object executeScript(String script, Object... args);
114
Object executeAsyncScript(String script, Object... args);
115
116
// Screenshots
117
<X> X getScreenshotAs(OutputType<X> target) throws WebDriverException;
118
```
119
120
### Chrome DevTools Protocol Support
121
122
EdgeDriver provides CDP support through inherited HasCasting and HasCdp interfaces:
123
124
```java { .api }
125
// CDP execution
126
Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters);
127
128
// Network domain
129
void createNetworkConditions(String name, boolean offline, long latency, long downloadThroughput, long uploadThroughput);
130
131
// Performance domain
132
List<Object> getPerformanceLogs();
133
134
// Casting capabilities (inherited from HasCasting)
135
List<Map<String, String>> getCastTargets();
136
void startTabMirroring(String deviceName);
137
void stopCasting(String deviceName);
138
String getCastIssueMessage();
139
```
140
141
**CDP Usage Examples:**
142
143
```java
144
import org.openqa.selenium.devtools.HasDevTools;
145
import org.openqa.selenium.devtools.DevTools;
146
147
EdgeDriver driver = new EdgeDriver();
148
149
// Enable network tracking
150
DevTools devTools = driver.getDevTools();
151
devTools.createSession();
152
devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
153
154
// Listen to network events
155
devTools.addListener(Network.responseReceived(), response -> {
156
System.out.println("Response: " + response.getResponse().getUrl());
157
});
158
159
// Execute CDP commands directly
160
Map<String, Object> result = driver.executeCdpCommand("Runtime.evaluate",
161
Map.of("expression", "window.location.href"));
162
```
163
164
### Error Handling
165
166
EdgeDriver throws standard WebDriver exceptions:
167
168
```java { .api }
169
// Common exceptions
170
WebDriverException - General WebDriver errors
171
SessionNotCreatedException - When driver session cannot be created
172
NoSuchElementException - When element is not found
173
TimeoutException - When operations timeout
174
ElementNotInteractableException - When element cannot be interacted with
175
StaleElementReferenceException - When element reference is stale
176
```
177
178
**Error Handling Examples:**
179
180
```java
181
try {
182
EdgeDriver driver = new EdgeDriver();
183
driver.get("https://example.com");
184
185
WebElement element = driver.findElement(By.id("missing-element"));
186
} catch (SessionNotCreatedException e) {
187
System.err.println("Cannot create Edge session: " + e.getMessage());
188
} catch (NoSuchElementException e) {
189
System.err.println("Element not found: " + e.getMessage());
190
} catch (WebDriverException e) {
191
System.err.println("WebDriver error: " + e.getMessage());
192
} finally {
193
if (driver != null) {
194
driver.quit();
195
}
196
}
197
```
198
199
### WebView2 Support
200
201
EdgeDriver supports WebView2 automation when configured with appropriate options:
202
203
```java
204
EdgeOptions options = new EdgeOptions();
205
options.useWebView(true);
206
EdgeDriver driver = new EdgeDriver(options);
207
208
// WebView2 applications can now be automated
209
driver.get("webview2://app-content");
210
```
211
212
## Types
213
214
```java { .api }
215
import org.openqa.selenium.WebDriver;
216
import org.openqa.selenium.WebElement;
217
import org.openqa.selenium.By;
218
import org.openqa.selenium.chromium.ChromiumDriver;
219
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
220
import org.openqa.selenium.remote.http.ClientConfig;
221
import org.openqa.selenium.devtools.HasDevTools;
222
import org.openqa.selenium.devtools.HasCasting;
223
```