Microsoft Edge WebDriver implementation for Selenium WebDriver browser automation with EdgeOptions configuration and EdgeDriverService management.
—
EdgeOptions provides configuration and capability management for EdgeDriver with Edge-specific options, WebView2 support, and comprehensive browser customization capabilities inherited from ChromiumOptions.
Configuration class for EdgeDriver-specific browser options and capabilities.
/**
* Class to manage options specific to EdgeDriver.
*/
public class EdgeOptions extends ChromiumOptions<EdgeOptions> {
/** Key used to store EdgeOptions in a Capabilities object */
public static final String CAPABILITY = "ms:edgeOptions";
/** Key for Edge logging preferences */
public static final String LOGGING_PREFS = "ms:loggingPrefs";
/** Browser name for WebView2 automation */
public static final String WEBVIEW2_BROWSER_NAME = "webview2";
/**
* Creates default EdgeOptions with Edge browser name
*/
public EdgeOptions();
/**
* Enables or disables WebView2 automation mode
* @param enable true to enable WebView2 mode, false for regular Edge
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions useWebView(boolean enable);
/**
* Merges additional capabilities with these options
* @param extraCapabilities Capabilities to merge
* @return new EdgeOptions instance with merged capabilities
*/
public EdgeOptions merge(Capabilities extraCapabilities);
}Usage Examples:
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.PageLoadStrategy;
// Basic options
EdgeOptions options = new EdgeOptions();
// WebView2 mode
EdgeOptions webViewOptions = new EdgeOptions();
webViewOptions.useWebView(true);
// Merge capabilities
EdgeOptions baseOptions = new EdgeOptions();
EdgeOptions merged = baseOptions.merge(new ImmutableCapabilities(
CapabilityType.PAGE_LOAD_STRATEGY, PageLoadStrategy.NONE
));Set the path to the Edge executable for custom installations.
/**
* Sets the path to the Edge executable
* @param path File path to Edge executable
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setBinary(File path);
/**
* Sets the path to the Edge executable
* @param path String path to Edge executable
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setBinary(String path);Usage Examples:
EdgeOptions options = new EdgeOptions();
options.setBinary("/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge");
// Or with File object
options.setBinary(new File("/path/to/msedge"));Add command line arguments to customize Edge browser behavior.
/**
* Adds command line arguments to pass to Edge
* @param arguments Variable number of string arguments
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions addArguments(String... arguments);
/**
* Adds command line arguments from a list
* @param arguments List of string arguments
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions addArguments(List<String> arguments);Usage Examples:
EdgeOptions options = new EdgeOptions();
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--window-size=1920,1080");
// Multiple arguments at once
options.addArguments("--no-sandbox", "--disable-dev-shm-usage");
// From list
List<String> args = Arrays.asList("--incognito", "--disable-extensions");
options.addArguments(args);Add browser extensions to the Edge instance.
/**
* Adds extension files to be loaded in Edge
* @param paths Variable number of File objects pointing to .crx files
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions addExtensions(File... paths);
/**
* Adds base64-encoded extensions to be loaded in Edge
* @param encoded Variable number of base64-encoded extension strings
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions addEncodedExtensions(String... encoded);Usage Examples:
EdgeOptions options = new EdgeOptions();
// Add extension files
options.addExtensions(new File("/path/to/extension.crx"));
options.addExtensions(
new File("/path/to/ext1.crx"),
new File("/path/to/ext2.crx")
);
// Add base64-encoded extensions
String encodedExt = Base64.getEncoder().encodeToString(extensionBytes);
options.addEncodedExtensions(encodedExt);Set experimental options for Edge browser features.
/**
* Sets an experimental option for Edge
* @param name Name of the experimental option
* @param value Value for the experimental option
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setExperimentalOption(String name, Object value);Usage Examples:
EdgeOptions options = new EdgeOptions();
// Enable performance logging
options.setExperimentalOption("perfLoggingPrefs", Map.of(
"enableNetwork", true,
"enablePage", true
));
// Custom download directory
options.setExperimentalOption("prefs", Map.of(
"download.default_directory", "/custom/download/path"
));
// Device emulation
options.setExperimentalOption("mobileEmulation", Map.of(
"deviceName", "iPhone 12"
));Configure standard browser behavior options.
/**
* Enables or disables headless mode
* @param headless true for headless mode, false for headed mode
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setHeadless(boolean headless);
/**
* Sets whether to accept insecure certificates
* @param accept true to accept insecure certificates
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setAcceptInsecureCerts(boolean accept);
/**
* Sets the page load strategy
* @param strategy PageLoadStrategy (NORMAL, EAGER, NONE)
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setPageLoadStrategy(PageLoadStrategy strategy);
/**
* Sets unhandled prompt behavior
* @param behaviour UnexpectedAlertBehaviour for handling prompts
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setUnhandledPromptBehaviour(UnexpectedAlertBehaviour behaviour);
/**
* Sets target platform
* @param platform Platform specification
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setPlatformName(Platform platform);Usage Examples:
EdgeOptions options = new EdgeOptions();
options.setHeadless(true);
options.setAcceptInsecureCerts(true);
options.setPageLoadStrategy(PageLoadStrategy.EAGER);
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS);
options.setPlatformName(Platform.WINDOWS);Set and retrieve arbitrary capabilities.
/**
* Sets a capability value
* @param key Capability name
* @param value Capability value
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions setCapability(String key, Object value);
/**
* Gets a capability value
* @param capabilityName Name of the capability
* @return Capability value or null if not set
*/
public Object getCapability(String capabilityName);
/**
* Gets browser name capability
* @return Browser name ("MicrosoftEdge" or "webview2")
*/
public String getBrowserName();
/**
* Converts options to a capabilities map
* @return Map of capability names to values
*/
public Map<String, Object> asMap();Usage Examples:
EdgeOptions options = new EdgeOptions();
// Set custom capabilities
options.setCapability("customCapability", "customValue");
options.setCapability("timeouts", Map.of(
"implicit", 10000,
"pageLoad", 30000
));
// Get capabilities
String browserName = options.getBrowserName();
Object timeout = options.getCapability("timeouts");
// Convert to map for inspection
Map<String, Object> caps = options.asMap();Configure Edge for WebView2 application automation.
/**
* Changes browser name to 'webview2' to enable WebView2 app automation
* @param enable true to enable WebView2 mode, false for regular Edge
* @return this EdgeOptions instance for method chaining
*/
public EdgeOptions useWebView(boolean enable);Usage Examples:
EdgeOptions options = new EdgeOptions();
// Enable WebView2 mode
options.useWebView(true);
String browserName = options.getBrowserName(); // Returns "webview2"
// Disable WebView2 mode
options.useWebView(false);
browserName = options.getBrowserName(); // Returns "MicrosoftEdge"
// Use with EdgeDriver
EdgeDriver driver = new EdgeDriver(options);
driver.get("webview2://embedded-app");import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.Platform;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.chromium.ChromiumOptions;
import org.openqa.selenium.remote.CapabilityType;
// Enums
enum PageLoadStrategy {
NORMAL, EAGER, NONE
}
enum UnexpectedAlertBehaviour {
DISMISS, ACCEPT, DISMISS_AND_NOTIFY, ACCEPT_AND_NOTIFY, IGNORE
}
enum Platform {
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
}Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-edge-driver