Recommended Free Tools
If Selenium does not save a screenshot, first distinguish a capture failure from a file-write failure. In Python, pass an absolute filename ending in .png, create the parent directory yourself, and check the boolean returned by save_screenshot(). A return value of False means Selenium encountered an I/O error; an exception usually indicates a driver, browser, or unsupported-capture problem.
Use a known, writable path first
This is a minimal Python pattern that handles the most common cause: a missing directory or an ambiguous relative path.
from pathlib import Path
from selenium import webdriver
output_dir = Path("/absolute/path/to/screenshots")
output_dir.mkdir(parents=True, exist_ok=True)
output_file = output_dir / "page.png"
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
saved = driver.save_screenshot(str(output_file))
if not saved:
raise OSError(f"Selenium could not write screenshot to {output_file}")
print(f"Saved {output_file.resolve()}")
finally:
driver.quit()
Selenium’s Python API saves a PNG to the exact filename supplied. It does not promise to create missing parent directories. The API recommends a full path and returns True when the write succeeds and False for an I/O error. The mkdir call above is ordinary Python filesystem handling, not a Selenium feature.
Diagnose the failure in the right order
-
Look for an exception before checking the file
A thrown Selenium exception means the capture operation or driver failed. Typical examples include a browser that has exited, an invalid session, a page-load problem that prevents the command from completing, or a driver that does not support screenshots. Java’s API documents
WebDriverExceptionfor capture failure andUnsupportedOperationExceptionwhen capture is unsupported. This is different from a successful capture followed by a local write error.The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Check Python’s return value
Do not infer success merely because the call did not throw. Both
save_screenshot(filename)andget_screenshot_as_file(filename)return a boolean. AFalseresult reports an I/O error, so log the resolved path and stop the test rather than silently continuing. -
Resolve the path and working directory
A path such as
screenshots/page.pngis relative to the process working directory, which may differ between a terminal, IDE, notebook, test runner, CI job, and container. PrintPath.cwd(), resolve the destination, and use an absolute path while diagnosing.from pathlib import Path print("working directory:", Path.cwd()) print("destination:", output_file.resolve()) print("parent exists:", output_file.parent.exists()) print("parent writable:", output_file.parent.is_dir())The final check is only a directory check; operating-system permissions still determine whether the Selenium process can create the file.
-
Verify the parent directory and filename
Create the directory with
parents=Trueandexist_ok=True. Confirm that the account running the browser test can write there. Check for invalid characters, reserved names, an overlong path, a read-only mount, or a filename that is actually a directory. Always include.png; do not rely on Selenium to infer an extension.Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Confirm which machine owns the path
With Selenium Grid, a remote WebDriver, CI worker, Docker container, or hosted browser, the path belongs to the machine running the test code and binding—not necessarily your workstation or the machine displaying the browser. Find the artifact in that environment, or copy it to a location your CI system publishes. Remote providers have different artifact-transfer behavior; a remote screenshot does not automatically appear in a local folder.
Python saving methods and controlled alternatives
save_screenshot()
Use this convenience method when you want Selenium to obtain PNG bytes and write the file. It delegates to the same file-saving behavior as get_screenshot_as_file().
path = Path("/absolute/path/to/screenshots/home.png")
path.parent.mkdir(parents=True, exist_ok=True)
if not driver.save_screenshot(str(path)):
raise OSError(f"Screenshot write failed: {path}")
get_screenshot_as_file()
This method has the same PNG filename and boolean-result contract. It is useful when code already follows the “get” naming convention, but it does not solve directory permissions or remote-filesystem issues.
if not driver.get_screenshot_as_file(str(path)):
raise OSError("Selenium reported an image-write I/O error")
Save bytes yourself
When you need to control storage, transmission, or artifact naming separately from capture, request raw PNG bytes and write them with Python.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallpng = driver.get_screenshot_as_png()
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(png)
# Or transmit an encoded value when a binary file is not convenient:
encoded = driver.get_screenshot_as_base64()
This separates browser capture from filesystem storage. Your own write_bytes() call then raises a filesystem exception that you can log precisely.
Java: obtain the temporary file, then copy it
Java’s screenshot API uses the TakesScreenshot interface. Requesting OutputType.FILE gives you a file produced by the driver; copying that file to your chosen directory is a separate operation.
Rank #3
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
File source = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File destination = new File("/absolute/path/to/screenshots/page.png");
File parent = destination.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Could not create " + parent);
}
FileUtils.copyFile(source, destination);
} finally {
driver.quit();
}
Handle the destination directory and Java I/O exceptions in your application. If the capture call throws, investigate driver support; if the copy fails, investigate the destination filesystem.
What a WebDriver screenshot actually contains
A normal screenshot is tied to the current WebDriver or WebElement browsing context. W3C-conformant implementations follow the WebDriver screenshot specification, while non-conformant implementations may vary. Do not assume that a regular call always captures the entire page from top to bottom, or that a missing file proves a full-page limitation. If you require a full-page image, verify support for the specific browser, driver, Selenium binding, and full-page mechanism you selected.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesAlso ensure you are capturing the intended context: switch to the correct window or frame before calling the screenshot method, and capture an element explicitly when the requirement is an element rather than the viewport.
Common symptoms, causes, and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
Method returns False |
Local I/O error while opening or writing the filename | Create the parent directory, use an absolute .png path, verify permissions and filename validity, and log the resolved destination. |
FileNotFoundError or “no such file or directory” |
Parent directory does not exist, or a relative path resolves somewhere unexpected | Call mkdir(parents=True, exist_ok=True) and print Path.cwd() and path.resolve(). |
| Permission or access-denied error | The test account cannot write to the directory or the mount is read-only | Choose a writable test-artifact directory or adjust permissions according to your operating system and CI policy. |
| No exception, but you cannot find the file | The file was written in the runner, container, Grid node, or another working directory | Inspect the filesystem belonging to the test process and configure artifact collection or transfer. |
WebDriverException |
Capture or browser-session failure | Check that the driver session is alive, the browser and driver are compatible, and the command runs in a supported context. |
UnsupportedOperationException in Java |
The selected driver does not support screenshots | Use a driver/browser combination that implements the screenshot command or change the capture strategy. |
| Image exists but is not the expected page | Wrong window, frame, element, viewport, or page state | Switch to the intended context, wait for the required state, and capture after navigation and rendering are complete. |
| Only part of a long page appears | Standard screenshot behavior is viewport or implementation dependent | Use and verify a browser-specific full-page facility rather than assuming ordinary screenshots are full-page. |
Remote, CI, and container checks
- Print the hostname, current working directory, and resolved screenshot path from the test process.
- Check that the destination is inside a writable workspace; some containers mount the application directory read-only.
- Give each test a unique filename to avoid collisions between parallel workers.
- Publish the directory as a CI artifact after the test finishes; a file that exists inside an ephemeral container disappears when the container is removed.
- Do not treat a provider’s browser display as evidence that the Python process writes to your laptop. The writer is the environment executing the Selenium command.
Reliability and performance practices
Fail loudly and preserve diagnostics
Wrap the capture in try/finally so the driver is closed, and raise on a false return. Include the URL, test name, worker identifier, and resolved path in logs. This distinguishes a capture failure from a storage failure in a single test run.
Use deterministic names and directories
Derive names from a sanitized test identifier and add a timestamp or worker suffix when tests run concurrently. Keep the extension .png and avoid relying on process-specific temporary directories unless your artifact collector knows about them.
Rank #4
Capture at the right point
Navigate first, wait for the application state your assertion requires, switch to the intended browsing context, and then capture. A valid file can still be visually wrong if the page has not rendered or the wrong tab is active.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Separate capture from retention
Saving bytes locally is usually simpler than debugging a provider-specific file-transfer rule. For remote runs, write to the worker’s known artifact directory or upload the bytes through your CI’s supported mechanism.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF, so there is no Selenium driver, browser binary, or local screenshot directory to configure.
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 documentation for request options. The service accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and whether the request was billed.
For 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)
For 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}`);
Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Features include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF controls, custom CSS and JavaScript, click-before-capture, selector hiding, selector/delay/network-idle waits, request and resource blocking, custom headers/cookies/user agents and Authorization, timezone and geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs.
The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account to get started.
Best Value
FAQ
Does Selenium create the screenshot directory automatically?
No. Create the parent directory with your language’s filesystem APIs before calling the screenshot method.
Why does a screenshot call return false instead of throwing?
Python reports an I/O failure through the boolean return value. Check it explicitly and log the full destination path.
Where is a screenshot saved when using Selenium Grid?
It is saved in the filesystem of the process and node handling the command, according to your execution setup. Configure artifact transfer rather than assuming it is on the local workstation.
Can a normal WebDriver screenshot guarantee a full-page image?
No. Coverage depends on the browser, driver, binding, and implementation. Verify the full-page capability you intend to use.
Quick Recap
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.




