ScreenshotNeo

BlogHow-to

How to Fix Selenium IE Driver SessionNotFoundException

Trace the deleted WebDriver session, validate IE Mode and IEDriverServer settings, then fix teardown, concurrency, and legacy IE configuration issues.

By the ScreenshotNeo team30 September 20269 min read

How to Fix Selenium IE Driver SessionNotFoundException

Direct answer: Selenium’s SessionNotFoundException usually means the WebDriver session was already deleted or changed before the failing command ran. Start by tracing driver.quit(), driver.close(), test teardown, fixture cleanup, browser restarts, and other threads that might close the last tab. Only after confirming the lifecycle should you investigate IE Driver configuration.

For legacy Internet Explorer automation, also verify which browser is actually running. Selenium no longer officially supports standalone Internet Explorer as of June 2022; the supported legacy route is the Internet Explorer Driver controlling Microsoft Edge in IE Compatibility Mode. The same session-lifecycle checks still apply, but the browser and driver configuration are different.

What the exception means

A WebDriver session has an identifier held by the client and the driver server. Every command, such as finding an element or navigating, is sent using that identifier. A session-not-found error means the server can no longer find the session, or the session state changed before the command arrived. Selenium’s error documentation lists deleting the session with quit() and closing the last browser window or tab as typical causes (official error documentation).

Trace the session from creation through teardown to find which action removed it.
Trace the session from creation through teardown to find which action removed it.

This is different from SessionNotCreatedException. A creation exception means the browser session never started successfully and usually points to browser/driver compatibility, permissions, or startup configuration. A session-not-found exception normally occurs after creation, although a startup crash can make the session disappear immediately.

1. Find the first point where the session disappeared

  1. Save the complete stack trace and the IEDriverServer log.
  2. Locate the first WebDriver command that fails, rather than the final assertion that reports the failure.
  3. Search the codebase for quit(), close(), browser-restart helpers, fixture cleanup, and teardown hooks.
  4. Check whether a failed setup or finally block closes the driver before the test body uses it.
  5. Check whether another test, thread, or parameterized case shares the same driver instance.

driver.close() closes the current window. If it was the last window, the browser session can no longer accept normal commands. driver.quit() ends the entire session and should normally run once, at the end of the test scope. Do not call either method from code that can run while another test still owns the driver.

Minimal lifecycle logging

WebDriver driver = null;
try {
    driver = new InternetExplorerDriver();
    System.out.println("session=" + ((RemoteWebDriver) driver).getSessionId());
    driver.get("https://example.test");
    // Test commands go here.
} finally {
    if (driver != null) {
        System.out.println("quitting session=" + ((RemoteWebDriver) driver).getSessionId());
        driver.quit();
    }
}

Log the session ID immediately after construction and before teardown. If the failing command uses a different ID, a shared or reassigned driver is involved. If the ID is unchanged but the server log shows an exit, investigate the browser process, machine settings, and driver crash.

2. Confirm that a session was created

Do not apply session-not-found fixes to an exception thrown by the driver constructor. Preserve the original exception and determine whether the constructor returned. A creation failure commonly comes from an incompatible browser and driver, a missing executable, blocked process creation, or invalid capabilities. Selenium documents these separately from session deletion.

IE Driver reliability depends on a consistent browser and Windows configuration.
IE Driver reliability depends on a consistent browser and Windows configuration.
try {
    InternetExplorerOptions options = new InternetExplorerOptions();
    WebDriver driver = new InternetExplorerDriver(options);
    System.out.println("Created: " + ((RemoteWebDriver) driver).getSessionId());
} catch (SessionNotCreatedException e) {
    System.err.println("The session was never created: " + e.getMessage());
    throw e;
} catch (SessionNotFoundException e) {
    System.err.println("The session existed, then disappeared: " + e.getMessage());
    throw e;
}

3. Use the supported IE path

Selenium’s IE documentation states: “As of June 2022, Selenium officially no longer supports standalone Internet Explorer.” The Internet Explorer Driver can still run Microsoft Edge in IE Compatibility Mode, which is the route to evaluate for applications that require legacy IE behavior (Selenium IE Driver documentation).

IE Driver 4.5.0 and later can discover Edge automatically. When Internet Explorer is absent, the driver can use Edge. When both browsers are present, set the Edge attachment option described by the binding and version you use. Confirm the exact capability names in the documentation for your Selenium language binding; do not copy a capability from a different binding without checking its spelling and type.

InternetExplorerOptions options = new InternetExplorerOptions();
// Use the IE Driver capability for Edge IE Compatibility Mode
// documented for your Selenium binding/version.
WebDriver driver = new InternetExplorerDriver(options);

If the application can run in a current browser without IE-specific behavior, compare the same test in Edge or Chrome. Selenium recommends cross-browser comparison to separate application and synchronization defects from driver-specific defects.

4. Make IEDriverServer observable

The IEDriverServer executable must be discoverable on PATH, or Java can receive its location through the webdriver.ie.driver system property. Start with a diagnostic log file and a level that captures the failure. The server supports FATAL, ERROR, WARN, INFO, DEBUG, and TRACE.

System.setProperty("webdriver.ie.driver", "C:\\tools\\IEDriverServer.exe");
InternetExplorerDriverService service = new InternetExplorerDriverService.Builder()
    .withLogFile(new File("iedriver.log"))
    .withLogLevel(InternetExplorerDriverLogLevel.DEBUG)
    .build();

WebDriver driver = new InternetExplorerDriver(service, new InternetExplorerOptions());

On failure, inspect the final lines of the log. A clean server shutdown after quit() points to normal teardown. A process exit during navigation or element lookup points toward browser termination, a protected-mode mismatch, an unsupported hosting context, or a driver defect.

5. Correct IE 11 machine settings

Legacy IE automation is sensitive to Windows and browser settings. Apply these checks on the machine that runs the test:

  • FEATURE_BFCACHE: For IE 11, create the FEATURE_BFCACHE registry key if it is absent and set the iexplore.exe DWORD value to 0, as described in Selenium’s IE setup guidance.
  • Protected Mode: Use the same enabled or disabled state for every IE security zone.
  • Enhanced Protected Mode: Disable it for the supported legacy configuration.
  • Zoom: Set browser zoom to 100%.
  • Display scaling: Set Windows 10 display scaling to 100% on the automation host.

Selenium exposes an ignoreProtectedModeSettings option, but its documentation warns that bypassing the settings can lead to flaky tests, unresponsive behavior, or browser hangs. Match the settings manually first. Use the bypass only when you understand the risk and have isolated the run to a disposable test machine.

6. Remove shared-driver and concurrency hazards

A driver should have one clear owner. Create it in a test fixture with the same lifetime as the tests that use it, and dispose it in one teardown path. Do not store one mutable IE driver in a global singleton when tests can run concurrently.

public final class BrowserFixture {
    private WebDriver driver;

    public void start() {
        driver = new InternetExplorerDriver();
    }

    public WebDriver driver() {
        if (driver == null) {
            throw new IllegalStateException("Driver has not started");
        }
        return driver;
    }

    public void stop() {
        if (driver != null) {
            driver.quit();
            driver = null;
        }
    }
}

Selenium notes that multiple simultaneous IE Driver instances are possible but largely untested and may have cookie or focus problems. If parallel execution is required, isolate browsers with RemoteWebDriver and separate virtual machines or clean worker sessions. Selenium also states that IE Driver is unsupported under a Windows Service because service processes have different requirements. Run it in an interactive user session or use a supported remote execution design.

7. Fix synchronization before increasing arbitrary waits

Timing can make a browser appear to vanish when a test races navigation, redirects, or cleanup. Replace fixed sleeps with conditions tied to the page state. A temporary longer wait can tell you whether timing is involved, but keep the final wait specific.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
driver.get("https://example.test");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ready")));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.submit"))).click();

Never continue issuing commands after a test has intentionally quit the driver. If a retry is needed, create a new driver and record the old session as failed; do not reuse the old object.

8. A small reproducible IE test

Reduce the failure to one URL, one driver, and one command. This separates environment problems from application behavior.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class IeSmoke {
    public static void main(String[] args) {
        WebDriver driver = new InternetExplorerDriver();
        try {
            driver.get("https://example.test");
            System.out.println(driver.getTitle());
        } finally {
            driver.quit();
        }
    }
}

If this fails before navigation, inspect driver discovery, browser mode, registry settings, and logs. If it succeeds but the full suite fails, focus on fixture scope, parallelism, redirects, and code that closes windows.

Common errors and fixes

Symptom Likely cause Fix
SessionNotFoundException after another test finishes Shared driver was quit by another test or fixture Give each test worker its own driver and one teardown owner.
Error follows close() The last browser window was closed Use quit() only during final teardown; create a new session after closing the last window.
Exception occurs in the constructor SessionNotCreatedException or startup crash Keep the original exception, verify driver/browser compatibility, executable path, and capabilities.
Works manually but fails in CI Different user profile, display scaling, security zones, or service context Run with an interactive supported account, align IE settings, and collect IEDriverServer logs.
Browser hangs after bypassing protected mode ignoreProtectedModeSettings exposed an unstable configuration Restore matching Protected Mode settings across all zones.
Fails only with parallel tests IE Driver focus, cookies, or process contention Serialize IE tests or isolate workers with RemoteWebDriver and virtual machines.
Driver exits during a page load Legacy IE/Edge mode mismatch, browser crash, or unsupported page behavior Confirm Edge IE Compatibility Mode, inspect logs, and compare the URL in another browser.

Performance, reliability, and maintenance

  • Keep the reproduction small: One browser process and one URL produce more useful logs than a full suite.
  • Control the environment: Pin Selenium and driver versions, use a clean worker image, and record browser mode and Windows settings with each run.
  • Prefer supported browsers: If the application no longer needs IE behavior, migrate tests to Edge or another current browser. IE-specific workarounds add machine-level maintenance.
  • Separate retries from cleanup: A retry must create a new session. Retrying commands on a deleted session cannot restore it.
  • Collect evidence: Store the stack trace, session ID, driver log, browser mode, URL, and test worker identity for each failure.

Or skip the browser setup

If your goal is a reliable screenshot rather than interactive IE automation, ScreenshotNeo provides a single HTTP request for a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for all options.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.

Create a free ScreenshotNeo account and start with 1,000 screenshots each month at no charge.

FAQ

Can I fix this by calling driver.quit() earlier?

No. Calling quit() earlier deletes the session. The fix is to call it exactly once after all commands finish and to prevent other code from using that driver afterward.

Is standalone Internet Explorer still supported by Selenium?

Selenium says standalone Internet Explorer is no longer officially supported since June 2022. Use Edge IE Compatibility Mode when legacy behavior is required and your environment supports it.

Why does the error mention “no such session”?

That wording is the protocol-level description of a session ID that the driver server no longer owns. The practical causes are usually teardown, a closed last window, a browser or driver exit, or unsafe concurrency.

Should I use a longer implicit wait?

Implicit waits do not recreate a deleted session. Use explicit waits for page conditions, then investigate lifecycle and driver logs if the session still disappears.

What evidence should I attach to a bug report?

Include the full exception, first failing command, Selenium and IEDriverServer versions, browser mode, Windows settings, driver log, session ID, URL, and whether the run was parallel or hosted as a service.