Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

SessionNotFoundException during getScreenshotAs usually means Selenium is trying to capture an image after the WebDriver session has ended or changed. Check teardown order first: keep the same InternetExplorerDriver instance alive until the screenshot hook has run, and call close() or quit() afterward. In the matching JUnit incident, moving driver setup and teardown to @BeforeClass and @AfterClass fixed the failure.

What the exception means

A screenshot is a WebDriver command, not a separate recovery mechanism. The driver sends that command to the browser session it controls. If that session has been deleted or the last browser window has closed, the command has nowhere to go. Selenium’s common-errors documentation explains that this can happen after driver.quit(), or after driver.close() closes the last tab or browser.

That makes this different from a screenshot path, file-permission, or image-format problem. First determine whether the session is still alive when the screenshot code runs. Selenium also notes that poor synchronization is a common source of WebDriver errors; a wait can address a page that is not ready, but it cannot revive a deleted session. See Selenium’s troubleshooting guidance.

Fix the driver lifecycle before changing IE settings

Keep the session alive through failure handling

In the reported JUnit case, the driver received a close event before the screenshot rule ran. The accepted answer identified lifecycle ordering and fixed it by moving startup and shutdown from per-test @Before/@After methods to @BeforeClass/@AfterClass. That is a community-reported fix for that test arrangement, not a universal requirement for every test suite or IE setup. The key is that teardown must not happen before the failure screenshot handler.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Find every driver.close() and driver.quit() call, including test rules, listeners, hooks, and cleanup code.
  2. Ensure the screenshot hook runs before any code closes the final browser window or quits the session.
  3. Use the same WebDriver object that executed the test. Do not create a fresh InternetExplorerDriver inside a screenshot helper or page object.
  4. Keep cleanup in a guaranteed teardown path that runs after screenshot handling, including when a test fails.

For JUnit, put driver lifetime around the screenshot rule’s lifetime. The exact annotations and rule ordering depend on how the test class is structured; the incident’s @BeforeClass/@AfterClass change worked because it kept the session available until the rule captured the failure.

Confirm state immediately before capture

Log the session ID and window handles just before calling getScreenshotAs. If reading these properties itself fails with a session error, the problem is already session loss, not screenshot encoding. If the session is present but a window was closed, inspect the handle list and ensure the current window is valid. If the session has ended, record that the screenshot is unavailable for this failure rather than attempting to capture with a new, unrelated session.

For a Java test, the core capture operation should use the live driver instance:

File image = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

Import the Selenium screenshot interfaces and file type used by your Selenium version. Persist or attach the returned file before teardown. Creating a second driver may produce a screenshot of a new blank session, but it will not recover the state that caused the test failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separate synchronization errors from a dead session

If the browser is still open and the session responds, the page may simply not have reached the state your test expects. Wait for a meaningful condition before capture, such as the relevant element becoming visible or a loading indicator disappearing. Avoid relying only on fixed sleeps when an explicit condition is available. If the session has already been deleted, adding a wait will not help; fix teardown ordering instead.

  • Session commands fail immediately: investigate close(), quit(), browser exit, and test-rule order.
  • Session responds, but page content is incomplete: add an explicit wait for the state needed in the screenshot.
  • The same test works in another browser: compare IE driver and browser configuration as well as test lifecycle; this is evidence to investigate IE-specific behavior, not proof by itself.

Check Internet Explorer configuration

IE configuration can cause startup, connection, or responsiveness problems, but it is a separate branch from a screenshot hook running after the session has closed. Selenium’s Internet Explorer driver documentation describes these requirements and cautions.

Protected Mode and zoom

Use the same Protected Mode setting in every IE security zone. Selenium warns that bypassing this check with ignoreProtectedModeSettings can make tests flaky, unresponsive, or cause them to hang, so treat it as a fallback rather than the normal fix. Set browser zoom to 100%; IE driver’s native coordinate calculations rely on that setting.

IE11 BFCACHE setting

For IE11, the SeleniumHQ InternetExplorerDriver wiki documents setting the FEATURE_BFCACHE registry value named iexplore.exe to DWORD 0 so the driver can maintain its connection. Follow the registry path and configuration guidance for your Windows and IE installation in the SeleniumHQ InternetExplorerDriver wiki. Registry changes affect the machine’s browser behavior, so apply them only where you have permission and understand the impact.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Driver executable and supported launch context

Make IEDriverServer available on PATH or configure the webdriver.ie.driver system property with its executable path. Selenium’s IE Driver Server documentation says running IEDriverServer.exe under a Windows Service is explicitly unsupported and untested. If tests run as a service, reproduce the issue in a supported interactive context before attributing it to screenshot code.

Use clean-session and private-mode options only for their intended purpose

These capabilities can address shared browser state; they do not fix a screenshot attempted after teardown.

Option What it addresses Trade-off or limit
ie.ensureCleanSession=true Clears cache, history, and cookies for all running IE instances. Disabled by default; clearing state adds startup time and affects other running IE instances.
ie.forceCreateProcessApi=true with ie.browserCommandLineSwitches=-private Starts IE in private mode to avoid reusing ordinary shared session data. Does not keep a prematurely closed WebDriver session alive.
ignoreProtectedModeSettings Bypasses Selenium’s Protected Mode consistency check. Selenium warns this can result in flaky, unresponsive, or hanging tests; prefer consistent zone settings.

Use clean-session behavior when test contamination is the issue, accepting slower startup. Use private mode when shared session data is the target. Neither is a substitute for correct screenshot-hook ordering.

Enable IE driver logs to identify who ended the session

Configure the IE driver’s log output and choose an appropriate level: FATAL, ERROR, WARN, INFO, DEBUG, or TRACE. Start with a less verbose level and increase detail when needed. Compare timestamps around the failure, screenshot hook, and teardown to determine whether IE exited, the server lost its attachment, or test code closed the browser. Selenium documents IE driver logging and configuration in its IE driver guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why Augmenter is not the fix for this incident

The original report tried new Augmenter().augment(driver) and encountered a CGLIB IllegalAccessException. The accepted answer instead fixed the order in which the test closed the driver and invoked the screenshot rule. Unless your setup has a separate remote-driver capability issue, adding Augmenter does not solve a session that has already been deleted.

Or skip the browser setup

If your actual goal is to capture a website screenshot rather than preserve an IE test’s failing browser state, ScreenshotNeo provides a screenshot API and MCP server. This is not a replacement for a failure screenshot from the live Selenium session: it captures a URL in its own browser context.

One GET request returns an image or PDF. Example using cURL:

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

See the ScreenshotNeo API documentation for request options and response details. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides screenshot tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo’s free plan to try it with 1,000 screenshots a month and no card.

Quick troubleshooting checklist

  • Screenshot fails after a test failure: verify the hook runs before close() or quit(); keep the same driver instance alive.
  • Session vanishes intermittently: inspect test rules, listeners, and cleanup paths, then correlate them with IE driver logs.
  • Browser is open but the page is not ready: wait for the required page condition before capture.
  • IE hangs or behaves inconsistently: confirm Protected Mode matches across zones and zoom is 100%; avoid using the bypass capability as the first remedy.
  • IE11 connection drops: check the documented BFCACHE registry configuration and driver setup.
  • Test state leaks between runs: consider clean-session or private-mode capabilities, accounting for their distinct behavior and startup trade-offs.

Frequently Asked Questions

Can getScreenshotAs create a new WebDriver session if the old one is gone?

No. It sends a command to the existing session; once that session is deleted, capture from it is unavailable.

Does this fix apply to every Selenium and IE version?

No. The lifecycle change is documented for a particular JUnit incident. IE configuration and exact setup requirements can vary; use Selenium’s version-appropriate IE driver documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.