Use Selenium’s file-saving method with an explicit, writable path. In Python, the direct call is driver.save_screenshot('/absolute/path/to/screenshot.png'); it captures the current window as a PNG and returns False when Selenium cannot write the file. Create the destination directory first, use a .png filename, and check the return value.
This guide covers Python, Java, Ruby, C#, and JavaScript, explains what each binding actually captures, and shows how to diagnose path and filesystem failures. The method descriptions and behavior referenced here come from the Selenium Python WebDriver API, Selenium’s browser windows documentation, and the Java TakesScreenshot API.
Python: save the current window to a file
The simplest Python pattern is:
driver.save_screenshot('/absolute/path/to/screenshot.png')
The documented method saves the current browser window as a PNG. Selenium recommends a full path rather than relying on the process working directory, and the method returns a Boolean indicating whether the write succeeded.
A complete example with a checked result
from selenium import webdriver
from pathlib import Path
output = Path('/absolute/path/to/screenshots/page.png')
output.parent.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
driver.get('https://example.com')
saved = driver.save_screenshot(str(output))
if not saved:
raise OSError(f'Selenium could not write {output}')
print(f'Screenshot saved to {output}')
finally:
driver.quit()
The directory is created before navigation, so a missing parent folder does not cause an avoidable I/O failure. The finally block closes the WebDriver session even when navigation or saving raises an exception. Keep the extension as .png; these Python file-saving methods are documented for PNG output.
#1 Best Overall
Using a relative path deliberately
A relative path is resolved against the process’s current working directory, which can differ between a terminal, an IDE, a test runner, and CI. Use it only when that location is intentional:
saved = driver.save_screenshot('./artifacts/home.png')
if not saved:
raise OSError('Screenshot write failed')
For repeatable automation, print the resolved path or convert it to an absolute path before saving.
When you need image data instead of a file
The Python API also exposes get_screenshot_as_png(), which returns raw PNG bytes, and get_screenshot_as_base64(), which returns a Base64 string. These are useful when another API, database, or object store receives the image directly:
png_bytes = driver.get_screenshot_as_png()
with open('/absolute/path/to/screenshots/page.png', 'wb') as image:
image.write(png_bytes)
encoded = driver.get_screenshot_as_base64()
Use save_screenshot() when your goal is simply a durable file; use the byte or Base64 methods when your program must handle the representation itself.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #2
Java: copy the temporary screenshot to your destination
Java’s TakesScreenshot interface can return a screenshot as a temporary file, bytes, or Base64. With OutputType.FILE, copy that temporary file to a persistent destination before the JVM exits:
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;
public class SaveScreenshot {
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
File temporary = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
File destination = new File(
"/absolute/path/to/screenshots/page.png");
destination.getParentFile().mkdirs();
FileUtils.copyFile(temporary, destination);
} finally {
driver.quit();
}
}
}
The Selenium example uses Apache Commons IO’s FileUtils.copyFile. The temporary file is deleted when the JVM exits, so keeping its original path is not a durable-save strategy. The Java API also defines OutputType.BYTES and OutputType.BASE64 when you need to write or transmit the data yourself. See the Java OutputType API uses for those output forms.
Other Selenium bindings
The destination call is binding-specific; do not copy the Python method name into another language.
Ruby
driver.save_screenshot('./image.png')
Selenium’s browser-interactions examples use this Ruby form for a PNG file.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
C#
((ITakesScreenshot)driver).GetScreenshot()
.SaveAsFile("screenshot.png", ScreenshotImageFormat.Png);
The C# example obtains the screenshot and saves it with SaveAsFile, explicitly selecting PNG.
JavaScript with Node.js
const fs = require('fs');
const image = await driver.takeScreenshot();
fs.writeFileSync('/absolute/path/to/screenshots/page.png', image, 'base64');
The JavaScript example returns a Base64-encoded screenshot, and Node’s filesystem API writes that string to the chosen path. Ensure the parent directory exists and that the Node process has permission to write there. Selenium’s official windows and tabs documentation shows the binding-specific patterns; that page was last modified May 11, 2026.
What Selenium actually captures
The ordinary file method captures the current browsing window or context. It does not automatically mean “the entire page.” A page taller than the viewport can therefore produce an image of only the visible window, depending on the binding, browser, driver, and Selenium implementation.
Current window versus full-page output
Python’s save_screenshot() documentation specifically describes the current window. Java’s TakesScreenshot API supports a WebDriver or an HTML element, but notes that behavior outside a W3C-conformant implementation can depend on the browser. If you require a full-page image, verify the supported method and semantics for your exact language binding, browser, driver, and Selenium version rather than assuming the basic call will stitch the page.
Recommended Free Tools
Rank #4
Element screenshots
Where the binding exposes element capture, call the screenshot operation on the target element instead of the driver. The resulting scope is the element’s rendered region, not a promise of a full document image. Test this against the browser and driver versions used in production.
Paths, directories, and file safety
Use a path the process can write
- Prefer an absolute destination in local scripts and CI jobs.
- Create the parent directory yourself; Selenium’s save call does not make a missing directory part of your workflow.
- Check the Python Boolean result and treat
Falseas an I/O failure. - Confirm that the account running the browser process has write permission to the directory.
- Use the expected image extension, especially
.pngfor Python’s file-saving methods.
Avoid accidental overwrites
If each run must be retained, generate a unique filename before calling Selenium, for example by adding a test name and timestamp to the path. If replacement is intentional, make that policy explicit in your test or capture code so a later run does not silently destroy evidence you needed.
Capture in the intended browsing context
Selenium captures the active window or context. Switch to the correct tab, window, frame, or element before taking the screenshot, and perform the call while the WebDriver session is still alive. The image reflects the state at the instant the command executes, so place it after the navigation or interaction whose result you want to document.
Troubleshooting failed saves
| Symptom | Likely cause | Fix |
|---|---|---|
The call returns False in Python |
The destination cannot be written, commonly because the directory is missing or permissions deny the write. | Create the parent directory, switch to an absolute path, verify ownership and permissions, then check the Boolean again. |
| No file appears at the expected location | A relative path was resolved from a different working directory than you expected. | Print the process working directory or replace the relative path with an absolute one. |
| The filename has a non-PNG extension in Python | The documented file-saving methods are PNG-oriented. | Use a filename ending in .png; use the returned bytes or Base64 only when your own conversion pipeline is intentional. |
| Java’s temporary file disappears | OutputType.FILE produces a temporary file that is removed when the JVM exits. |
Copy it to your durable destination immediately with FileUtils.copyFile or another filesystem copy operation. |
| The image is only the viewport | The ordinary operation captures the current window, not an automatic full-page render. | Use a documented full-page or element-capable method supported by your binding, browser, driver, and Selenium version, and verify its behavior. |
| The image shows the wrong tab or state | The command ran in the current browsing context before the desired navigation or interaction completed. | Select the intended window or element and take the screenshot after the state you need is present. |
| JavaScript writes an invalid image | The screenshot value is Base64 but was written as ordinary text or with the wrong encoding. | Write it using the filesystem API’s Base64 option, as in fs.writeFileSync(path, image, 'base64'). |
Reliable automation patterns
Make the destination part of test setup
Resolve the output directory once, create it before the browser starts, and include the test or page identifier in each filename. This separates browser failures from filesystem failures and makes artifacts easy to collect in CI.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
Keep the browser session open until the write finishes
Call the screenshot method before driver.quit(). In Java, copy the temporary file before JVM shutdown; in every binding, handle the returned data or completed copy before ending the process.
Record what was captured
Alongside the image, record the URL, window or element scope, and the destination path in your test logs. This is especially useful when a current-window screenshot is mistaken for a full-page capture.
Or skip the browser setup
If you need a hosted screenshot rather than a Selenium session, ScreenshotNeo is the first service to try: it removes cookie banners, newsletter popups, and chat widgets before capture, and only clean shots are billed.
One GET request returns an image or PDF. The API base is https://api.screenshotneo.com/v1/shot; the complete parameter reference is in the ScreenshotNeo documentation.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →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 reports whether a response was a clean capture and whether it was billed through the X-Page-Verdict and X-Billed headers. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients, so AI agents can request captures without you maintaining browser drivers.
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to get started.
Frequently Asked Questions
Can ScreenshotNeo replace Selenium for browser interactions?
No. Selenium drives a browser for navigation and interaction; ScreenshotNeo is a screenshot API and MCP server that captures a URL, page information, or a PDF through its service endpoint.
Where can I verify the exact ScreenshotNeo request parameters?
Use the ScreenshotNeo documentation, which lists the API options and request formats.
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.

