Testing Electron and Desktop Apps
Automate Electron apps with Selenium: Java ElectronDriver, ChromeOptions binary plus matching chromedriver, window handling, and Appium for native Windows apps.
VS Code, Slack, Discord, Figma’s desktop app, Microsoft Teams (classic) and countless internal tools are Electron apps: a Chromium renderer plus Node.js, packaged as a desktop executable. Because the UI is a web page rendered by Chromium, Selenium can drive it with chromedriver, and all your existing skills (locators, waits, page objects) carry over directly.
Native desktop applications (WinForms, WPF, WinUI, Cocoa) are a different story: there is no DOM, and Selenium alone cannot see them. This lesson covers both: Electron in depth, and the WebDriver-compatible options for native desktop apps.
How Electron Automation Works
your test --W3C WebDriver--> chromedriver --DevTools protocol--> Electron app (Chromium renderer)Chromedriver does not care whether the Chromium it launches is Google Chrome or an Electron app; it starts the binary you give it with a remote debugging port and talks DevTools to it. The two things you must get right:
- The binary: the packaged app executable (or the Electron runtime plus your app’s source folder in development).
- A chromedriver that matches Electron’s embedded Chromium, not your installed Chrome. Each Electron release embeds one specific Chromium version, which usually lags Chrome stable by a version or more. A mismatched driver fails with
session not created: This version of ChromeDriver only supports Chrome version N(see Session Not Created).
Find the Chromium version of an app with process.versions.chrome in its DevTools console (if exposed), from the Electron release notes for the Electron version it bundles, or by running a test once and reading the version from the error message.
Java: ElectronOptions and ElectronDriver (4.45+)
Selenium 4.45 added first-class Electron support to the Java binding. ElectronOptions takes the app binary and ElectronDriver launches it, handling the Chromium-specific plumbing for you.
// Selenium Java 4.45 or laterElectronOptions options = new ElectronOptions();options.setBinary("C:\\Program Files\\Acme Desk\\AcmeDesk.exe"); // or .app/Contents/MacOS/<App> on macOSWebDriver driver = new ElectronDriver(options);
new WebDriverWait(driver, Duration.ofSeconds(20)) .until(ExpectedConditions.visibilityOfElementLocated(By.id("login")));driver.findElement(By.id("login")).click();The classes are new, and their package location and the full set of option methods (arguments, driver path, environment) are best checked against the Javadoc for your exact Selenium version. Because ElectronOptions builds on the Chromium options model, the familiar addArguments style of configuration applies. If you are on an older Java client or need behaviour ElectronDriver does not expose, the ChromeOptions approach below works in Java too.
Every Binding: ChromeOptions Binary Plus Matching Chromedriver
This is the classic approach, documented by the Electron project itself, and it works in all four bindings. Point ChromeOptions at the app executable and supply the matching chromedriver explicitly.
Get the driver from one of:
- Electron’s GitHub releases: each Electron release publishes
chromedriver-vX.Y.Z-<platform>-<arch>.zip. Use the one with the same Electron version as the app. - The
electron-chromedrivernpm package, versioned to match Electron (npm i -D electron-chromedriver@38).
Do not rely on Selenium Manager here. It resolves drivers for Chrome, and the version it detects (or fails to detect) from an Electron executable will not reliably map to the right chromedriver. An explicit driver path skips it.
ChromeOptions options = new ChromeOptions();options.setBinary("C:\\Program Files\\Acme Desk\\AcmeDesk.exe");options.addArguments("--disable-gpu-sandbox"); // only if your CI needs it// App-specific switches your app understands, e.g. a test profile directory:options.addArguments("--user-data-dir=" + Files.createTempDirectory("acme-test"));
ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(new File("drivers/electron-38/chromedriver.exe")) .build();
WebDriver driver = new ChromeDriver(service, options);from selenium import webdriverfrom selenium.webdriver.chrome.service import Serviceimport tempfile
options = webdriver.ChromeOptions()options.binary_location = r"C:\Program Files\Acme Desk\AcmeDesk.exe"options.add_argument(f"--user-data-dir={tempfile.mkdtemp(prefix='acme-test')}")
service = Service(executable_path=r"drivers/electron-38/chromedriver.exe")driver = webdriver.Chrome(service=service, options=options)const { Builder } = require('selenium-webdriver');const chrome = require('selenium-webdriver/chrome');const os = require('node:os');const path = require('node:path');const fs = require('node:fs');
const options = new chrome.Options().setChromeBinaryPath('C:\\Program Files\\Acme Desk\\AcmeDesk.exe').addArguments(`--user-data-dir=${fs.mkdtempSync(path.join(os.tmpdir(), 'acme-test'))}`);
// electron-chromedriver exposes the binary path matching its Electron versionconst service = new chrome.ServiceBuilder(require('electron-chromedriver').path);
const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).setChromeService(service).build();var options = new ChromeOptions{ BinaryLocation = @"C:\Program Files\Acme Desk\AcmeDesk.exe",};options.AddArgument($"--user-data-dir={Directory.CreateTempSubdirectory("acme-test").FullName}");
// Directory containing the Electron-matched chromedriver.exevar service = ChromeDriverService.CreateDefaultService(@"drivers\electron-38");
var driver = new ChromeDriver(service, options);If the electron-chromedriver package’s exported path property differs in the version you install, check its README; the point is to pass the matching binary to ServiceBuilder, wherever it comes from.
Development builds
Before the app is packaged, the binary is the Electron runtime from node_modules/electron/dist/ (electron.exe, Electron.app/Contents/MacOS/Electron, or electron), and the app folder is passed as an argument. The Electron docs show this as an app= argument:
binary: <repo>/node_modules/electron/dist/electron.exeargs: ["app=<repo>"] # or the path to your main.js / app folderTest against packaged builds in CI wherever possible. Packaging changes paths, ASAR archives, preload script locations and security settings, and bugs that only exist in the packaged app are exactly the ones users hit.
Working With Electron Windows
Each BrowserWindow the app opens is a separate window handle, so everything in Windows and Tabs applies. Two Electron-specific wrinkles:
- Splash screens and hidden windows. Many apps show a splash window, then open the main window and close the splash. The first handle may disappear under you (
NoSuchWindowException, see No Such Window). Wait until the window you want exists, identified by title or URL, then switch to it. - Background windows. Apps sometimes create hidden windows for background work. They show up in
getWindowHandles()too; filter by URL or title.
String mainHandle = new WebDriverWait(driver, Duration.ofSeconds(30)) .ignoring(NoSuchWindowException.class) .until(d -> { for (String handle : d.getWindowHandles()) { d.switchTo().window(handle); if (d.getCurrentUrl().contains("index.html#/main")) return handle; } return null; });
driver.switchTo().window(mainHandle);from selenium.common.exceptions import NoSuchWindowException
def main_window(d): for handle in d.window_handles: d.switch_to.window(handle) if "index.html#/main" in d.current_url: return handle return False
main_handle = WebDriverWait(driver, 30, ignored_exceptions=[NoSuchWindowException]).until(main_window)driver.switch_to.window(main_handle)const mainHandle = await driver.wait(async () => {for (const handle of await driver.getAllWindowHandles()) { try { await driver.switchTo().window(handle); if ((await driver.getCurrentUrl()).includes('index.html#/main')) return handle; } catch (e) { if (e.name !== 'NoSuchWindowError') throw e; // splash closed mid-iteration }}return false;}, 30000);
await driver.switchTo().window(mainHandle);var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));wait.IgnoreExceptionTypes(typeof(NoSuchWindowException));
var mainHandle = wait.Until(d =>{ foreach (var handle in d.WindowHandles) { d.SwitchTo().Window(handle); if (d.Url.Contains("index.html#/main")) return handle; } return null;});
driver.SwitchTo().Window(mainHandle);Electron app URLs are typically file://.../index.html, app://... or a custom protocol, often with a hash route. Log getCurrentUrl() once to learn what yours look like.
What Chromedriver Cannot Reach in Electron
The renderer is a web page. Anything outside it is native, and chromedriver cannot touch it:
| Not reachable via chromedriver | Workaround |
|---|---|
Native menus (application menu bar, context menus built with Menu) | Trigger the same action via a keyboard accelerator, or expose a test-only IPC hook |
Native dialogs (dialog.showOpenDialog, showMessageBox) | Stub them in test builds (an env var makes the main process return a fixed path) |
| System tray, notifications, dock/taskbar | Test the underlying handler in unit tests; verify notification payloads via a test hook |
| Main-process logic (Node.js side) | Unit/integration tests in Node; or executeScript against a test-only preload API |
| Auto-update flows | Point the updater at a local test feed; assert on the renderer’s update UI |
The pattern behind most workarounds: build test hooks into the app, enabled only when a test environment variable is set. For example, when ACME_E2E=1, the main process replaces dialog.showOpenDialog with a function that returns the path in ACME_E2E_OPEN_FILE. This is the same principle as test-only API endpoints in API-Assisted UI Tests: give tests a controlled way around what they cannot drive.
Passing environment variables to the app is done through the driver service, because chromedriver launches the app and the app inherits chromedriver’s environment. In Java, ChromeDriverService.Builder().withEnvironment(Map.of("ACME_E2E", "1")); in Python, Service(env={...}); in JavaScript, ServiceBuilder.setEnvironment({...}). Setting them on the test process before creating the driver also works when the driver inherits the parent environment.
Electron Caveats
- Single-instance apps. Apps that call
app.requestSingleInstanceLock()quit if another instance is running. Parallel tests on one machine then fight each other. Give each session its own--user-data-dir(if the app honours it) or run one session per machine/container. - Hardened builds. Some production builds disable DevTools or remote debugging through Electron fuses or command-line filtering. Chromedriver needs the debugging port, so test a build with those protections relaxed, or work with the app team on a test build flavour.
- Startup time. Electron apps can take 5 to 20 seconds to start, especially on first launch when they unpack or migrate data. Use a long initial wait for the first meaningful element and normal waits after that.
- Sandbox flags in CI. On Linux containers you may need
--no-sandbox(as with Chrome), and a virtual display (Xvfb) because Electron apps generally do not support a headless mode. Run underxvfb-runin CI. - Version upgrades. Every Electron upgrade changes the Chromium version, so the chromedriver must change with it. Pin the driver version alongside the Electron version in the repo (for example,
electronandelectron-chromedriverin the samepackage.json), so they cannot drift apart.
Native Desktop Apps: The WebDriver Landscape
For non-Electron apps you need a driver that speaks the WebDriver protocol to the operating system’s accessibility APIs instead of to a browser.
| Platform | Option | Status in 2026 | Notes |
|---|---|---|---|
| Windows | WinAppDriver (Microsoft) | Effectively unmaintained; last stable release several years old | Still works for many apps; needs Windows Developer Mode; JSON Wire-era protocol |
| Windows | Appium Windows driver (appium driver install windows) | Maintained by the Appium project | W3C front end that delegates to WinAppDriver underneath, so inherits its limits |
| Windows | NovaWindows driver (community Appium driver) | Active community project | Talks to UI Automation directly without WinAppDriver; worth evaluating for new projects |
| Windows (.NET) | FlaUI | Active | A .NET UIA library, not WebDriver; often the most reliable choice for .NET teams testing WPF/WinForms |
| macOS | Appium Mac2 driver | Maintained | Uses Apple’s XCTest; needs Xcode on the test machine |
| Linux | No mainstream WebDriver option | Niche | AT-SPI based tools (e.g. Dogtail) outside the WebDriver ecosystem |
With an Appium driver, test code looks like Selenium with different locators. Native UI elements have no CSS or DOM; you locate them by accessibility id (the AutomationId on Windows), name, class name or XPath over the accessibility tree.
// io.appium:java-clientimport io.appium.java_client.AppiumBy;import io.appium.java_client.windows.WindowsDriver;import io.appium.java_client.windows.options.WindowsOptions;
WindowsOptions options = new WindowsOptions() .setApp("C:\\Program Files\\Acme\\Ledger.exe");
WindowsDriver driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), options);driver.findElement(AppiumBy.accessibilityId("CustomerSearchBox")).sendKeys("Contoso");driver.findElement(AppiumBy.name("Search")).click();# pip install Appium-Python-Clientfrom appium import webdriverfrom appium.options.windows import WindowsOptionsfrom appium.webdriver.common.appiumby import AppiumBy
options = WindowsOptions()options.app = r"C:\Program Files\Acme\Ledger.exe"
driver = webdriver.Remote("http://127.0.0.1:4723", options=options)driver.find_element(AppiumBy.ACCESSIBILITY_ID, "CustomerSearchBox").send_keys("Contoso")driver.find_element(AppiumBy.NAME, "Search").click()// dotnet add package Appium.WebDriverusing OpenQA.Selenium.Appium;using OpenQA.Selenium.Appium.Windows;
var options = new AppiumOptions{ AutomationName = "Windows", PlatformName = "Windows", App = @"C:\Program Files\Acme\Ledger.exe",};
var driver = new WindowsDriver(new Uri("http://127.0.0.1:4723"), options);driver.FindElement(MobileBy.AccessibilityId("CustomerSearchBox")).SendKeys("Contoso");driver.FindElement(MobileBy.Name("Search")).Click();Practical advice for native desktop automation:
- Ask developers for automation IDs.
AutomationId(Windows) and accessibility identifiers (macOS) are thedata-testidof desktop apps. Without them you are stuck with fragile name and XPath locators. They also improve accessibility for real users. - Use an inspector. Microsoft’s Accessibility Insights or
inspect.exe(Windows SDK), and Appium Inspector, show the accessibility tree and the properties you can locate by. - Desktop tests need an interactive session. Windows UI automation requires an unlocked, logged-in desktop. CI agents must run as an interactive user with auto-logon and no screen lock, not as a service.
- Expect slower, coarser tests than web automation: fewer, longer journeys focused on the highest-value workflows.
Choosing an Approach
| App type | Recommended tool |
|---|---|
| Electron app, Java team | ElectronDriver (4.45+) |
| Electron app, other languages | ChromeOptions binary + Electron-matched chromedriver |
| Electron app, native menus and dialogs matter | Selenium for the renderer + test hooks for native parts |
| Windows native (WPF, WinForms, WinUI) | FlaUI for .NET teams; Appium Windows or NovaWindows driver otherwise |
| macOS native | Appium Mac2 driver |
| Hybrid (native shell with web views) | Appium with context switching between native and web view |
Summary
- Electron apps are Chromium underneath, so chromedriver drives them and your Selenium skills transfer completely.
- Java 4.45+ has
ElectronOptions/ElectronDriver; in every binding,ChromeOptionswith the app binary and an Electron-matched chromedriver works. - Bypass Selenium Manager with an explicit driver path, and pin the driver version to the Electron version.
- Native menus, dialogs and the main process are out of reach; add environment-gated test hooks to the app.
- For native desktop apps, use Appium’s Windows or Mac2 drivers (or FlaUI on .NET), locate by accessibility IDs, and run on an interactive desktop session.
Finished this lesson?
Mark it complete to track your progress through the course. Saved in this browser only.