ScreenshotNeo

BlogHow-to

How to Fix WebDriverException When Taking a Screenshot of a Website on Mac

Find which Selenium step fails on macOS, then check the browser session, driver setup, and PNG output path. Includes a runnable Python example.

By the ScreenshotNeo team4 October 20268 min read

A Selenium WebDriverException while taking a website screenshot on a Mac does not point to one universal cause. First find the exact failing line: browser startup, navigation, the screenshot command, or saving the PNG. Then check the session and window state, browser and driver versions if startup failed, and the destination path if capture returned data but no file appeared.

Selenium’s documentation cautions that the root cause of an error is not always obvious. The complete exception and stack trace, plus your browser, driver, Selenium, and macOS versions, are needed to identify the cause in a particular setup. [Selenium troubleshooting](https://www.selenium.dev/documentation/webdriver/troubleshooting/)

1. Locate the failing step

Read the traceback and note the precise line that raises the exception. These stages have different fixes:

Failing stage What it tells you Start here
Driver constructor, such as webdriver.Chrome() No WebDriver session may have been created. Read the full startup error; inspect driver location, compatibility, and macOS execution or privacy restrictions.
driver.get(...) The session may exist, but navigation or page loading failed. Check the session is alive and the page is reachable; retain the exact navigation error.
save_screenshot(...) or another screenshot method The capture command failed in the current browser context. Check that the session and current window are still valid and that the driver has not been quit.
File is missing after the command Capture may have succeeded while writing failed. Check the return value, full output path, directory, and write access.

Do not assume a macOS permission setting is the cause merely because the computer is a Mac. Selenium lists macOS privacy settings and driver execution permission among possible causes of session creation failures; those checks apply when startup is failing, not as a generic cure for every screenshot exception. [Selenium common errors](https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/)

2. Check the live session and current window

A screenshot command requires an active WebDriver session and a valid current browsing context. A call to driver.quit() ends the session. Closing the last browser window can also leave subsequent commands without a valid window. If your code closes one of several windows, switch to a remaining valid window handle before continuing. Otherwise Selenium may report an invalid session or a No Such Window error. [Invalid session errors](https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/#invalid-session-id-exception) · [Window handling](https://www.selenium.dev/documentation/webdriver/interactions/windows/)

Review control flow around cleanup: a finally block should run after capture, not before it. Avoid sharing a driver that another function or thread may already have closed. When debugging, print the current window handle and available handles immediately before capture, and check that they are present.

3. If startup failed, inspect the Mac driver setup

Match Chrome and ChromeDriver

For Chrome, Selenium documents that the Chrome and ChromeDriver major versions must match. Check the installed Chrome version and the driver version actually being launched; a stale driver earlier on PATH can differ from the one you expect. [Selenium Chrome documentation](https://www.selenium.dev/documentation/webdriver/browsers/chrome/)

Check driver location and execution

Recent Selenium versions can use Selenium Manager to obtain a driver. If the exception specifically reports a missing or unlocated driver, check the Selenium version and driver-location setup. An explicit driver path or a correctly configured PATH are alternatives where needed. Do not change driver-location settings as a blanket response to an error raised later by the screenshot command. [Driver location](https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/)

If macOS reports that a driver cannot be executed or is blocked, verify that the binary exists and is executable, then review the exact macOS security or privacy message. Avoid weakening system security broadly; use the error details to identify the blocked binary and follow the applicable platform guidance.

4. Use a reliable Python screenshot and save pattern

Selenium’s Python screenshot methods capture the current browser window. The file methods save PNG data; use a full path with a .png extension, ensure the parent directory exists, and check the Boolean result. This example uses Chrome and a page URL as placeholders:

from pathlib import Path
from selenium import webdriver

out = Path.home() / "Downloads" / "page.png"
out.parent.mkdir(parents=True, exist_ok=True)

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
    ok = driver.save_screenshot(str(out))
    if not ok:
        raise OSError(f"Could not save screenshot to {out}")
    print(f"Saved screenshot to {out}")
finally:
    driver.quit()

The finally block ensures cleanup whether capture succeeds or raises. Keep the screenshot call before quit(). Replace the example URL and output path as appropriate. This pattern demonstrates the documented API behavior; it cannot identify a machine-specific startup or driver error without that error’s details. [Python WebDriver API](https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html)

Separate capture from file writing

If the file method returns false or writing is suspect, retrieve the screenshot bytes first and write them yourself. That helps distinguish a capture failure from a destination or filesystem problem:

from pathlib import Path
from selenium import webdriver

out = Path.home() / "Downloads" / "page.png"
out.parent.mkdir(parents=True, exist_ok=True)

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
    png_bytes = driver.get_screenshot_as_png()
    out.write_bytes(png_bytes)
    print(f"Wrote {len(png_bytes)} bytes to {out}")
finally:
    driver.quit()

Selenium also provides get_screenshot_as_base64() when a base64 string is more useful than bytes. These methods still require a live session and valid current window; separating the write does not repair a failed capture. [Python WebDriver API](https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html)

5. Troubleshoot by the symptom

Symptom or error detail Likely area Action
Exception occurs in webdriver.Chrome() Session startup Use the full startup message to check driver availability, Chrome/ChromeDriver major versions, executable permissions, and any macOS restriction named in the error.
Chrome starts, but screenshot command says session is invalid Session lifecycle Find an earlier quit() or other session deletion. Create a new driver session before issuing more commands.
No Such Window during capture Browsing context Check whether the active or last window was closed. Switch to an open window handle before capturing.
Screenshot call completes, but the expected file is absent File output Use an absolute path ending in .png; create its parent directory and inspect the method’s Boolean result and process write access.
Failure persists only in one browser Browser driver Reduce the case to a simple page and compare another supported browser where practical. Selenium notes that an issue reported through Selenium can originate in the underlying driver. [Troubleshooting](https://www.selenium.dev/documentation/webdriver/troubleshooting/)
Only certain pages fail Page or browser-specific behavior Record the page, navigation outcome, and exact capture exception. Test a simple known page to separate general setup from page-specific behavior.

6. Build a minimal reproduction

  1. Keep only driver creation, navigation to one simple page, one screenshot call, and cleanup.
  2. Record the full traceback and mark the exact failing line.
  3. Include macOS version, Selenium version, browser and driver names and versions, screenshot method, and output path.
  4. State whether a browser session started, whether navigation completed, and whether any window was closed before capture.
  5. If practical, compare another supported browser to help determine whether the underlying driver is involved.

This information makes a generic WebDriverException actionable. Without it, neither the exception name nor the fact that the machine runs macOS determines a single root cause.

Or skip the browser setup

If your goal is a website screenshot rather than browser automation, ScreenshotNeo provides a screenshot API and MCP server. One GET request returns an image or PDF; see the [ScreenshotNeo documentation](https://screenshotneo.com/docs/) for the API options. [ScreenshotNeo](https://screenshotneo.com) supports PNG, JPEG, and WebP output. For example, this cURL request saves a WebP screenshot:

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,
)
r.raise_for_status()
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}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', new Uint8Array(await res.arrayBuffer()));

Replace YOUR_API_KEY with your key and change the target URL. The cURL and Python examples save the response body as an image; in Node.js, the example uses Bun’s file writer. With plain Node.js, save the response bytes with node:fs/promises.

  • Cookie banners, popups, and chat widgets are removed before the shot.
  • Bot checks, blank pages, and failed loads are never billed; response headers report the page verdict and billing status.
  • An MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs.
  • 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000.

Sign up for 1,000 free screenshots a month, with no card required.

Performance, reliability, and cost notes

For Selenium, the browser startup, navigation, page loading, and screenshot operation all contribute to the work your script performs. Reuse a live session when taking multiple screenshots, and close it after the capture batch. Keep waits appropriate to the page rather than adding a long fixed delay to every run. File writing is separate from browser capture, so inspect it independently.

For repeatable automation, record versions and the exact failure stage, use a known output directory, and make cleanup explicit. A screenshot error can originate in the underlying browser driver, so compare browsers if a minimal reproduction continues to fail. No single version or Mac setting is a universal fix.

ScreenshotNeo charges only for clean shots: bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. Plans include Free (1,000 per month), Starter ($5 for 3,000), Growth ($15 for 15,000), Pro ($39 for 60,000), Scale ($99 for 250,000), and Business ($249 for 1,000,000); yearly billing gives two months free, and every feature is on every plan. Use the usage API and response billing headers to track usage and whether a request was billed.

FAQ

Does this error always mean ChromeDriver is incompatible?

No. Version mismatch is one startup possibility for Chrome. A generic exception may instead arise from an invalid session, a closed window, the capture operation, or file output.

Does Selenium’s file screenshot method save a full webpage?

The Python API describes these screenshot methods as capturing the current browser window. Do not assume the result includes the entire page beyond the visible window.

What details should I share when asking for help?

Include the full traceback, failing line, macOS and Selenium versions, browser and driver versions, screenshot method, output path, and whether the session and current window were still open.