Save a Selenium screenshot by passing the destination filename to the binding’s screenshot method. In Python, the direct call is driver.save_screenshot('/absolute/path/to/screenshot.png'). Use an existing, writable directory, prefer an absolute path, and check the Boolean result because Selenium returns False when it cannot write the file. This captures the current browser window; it is not automatically a full-page screenshot.
Python: save the current window to a PNG file
The Selenium Python WebDriver API documents save_screenshot(filename) as saving the current window to a PNG image file. A complete example is:
from pathlib import Path
from selenium import webdriver
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()
See the Selenium Python WebDriver API for the documented method. The parent directory is created explicitly because Selenium does not create missing folders for you. The process must have permission to write there.
Use a relative path deliberately
A path such as screenshots/page.png is resolved from the process working directory, which may differ between a terminal, IDE, test runner, and CI job. Selenium’s Python documentation recommends a full path. If you intentionally use a relative path, print Path.cwd() so you know where the file will be written.
#1 Best Overall
Check the return value
save_screenshot() returns a Boolean. A true value means the driver reported a successful write; a false value indicates an I/O failure. Do not silently continue when the result is false, especially in automated tests where a missing artifact can otherwise go unnoticed.
Python alternatives: bytes and Base64
If your application uploads or transforms the image instead of writing it directly, use the other methods listed by the Python API:
# PNG bytes
png_bytes = driver.get_screenshot_as_png()
with open('/absolute/path/to/screenshots/page.png', 'wb') as image_file:
image_file.write(png_bytes)
# Base64 text
png_base64 = driver.get_screenshot_as_base64()
The direct file method is simpler when the required result is a file. Bytes are useful for an object-storage client or an image-processing library; Base64 is useful when an API requires text encoding. When writing bytes yourself, open the destination in binary mode (wb).
Java: copy Selenium’s temporary file to your destination
Java uses the TakesScreenshot interface. With OutputType.FILE, Selenium returns a temporary file, not a permanent artifact at your chosen path. Copy it before the JVM exits:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteimport java.io.File;
import java.io.IOException;
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 IOException {
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");
FileUtils.copyFile(temporary, destination);
} finally {
driver.quit();
}
}
}
The official Selenium example uses Apache Commons IO’s FileUtils.copyFile. The Java TakesScreenshot API also defines BYTES and BASE64 output types. The OutputType API usage page documents those forms.
Java bytes or Base64
byte[] png = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
String base64 = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BASE64);
Write the byte array to a durable path with your normal Java file APIs, or pass the Base64 string to a system that expects it. Do not rely on the temporary FILE location after the Java process ends.
Rank #2
Other Selenium bindings
The destination mechanism is binding-specific. The Selenium documentation’s browser-interactions examples show these patterns:
| Binding | File-saving pattern | Important detail |
|---|---|---|
| Ruby | driver.save_screenshot('./image.png') |
Path is interpreted by the Ruby process; use an absolute path when the working directory is uncertain. |
| C# | driver.SaveAsFile("screenshot.png", ScreenshotImageFormat.Png) |
Choose the destination and PNG format explicitly. |
| JavaScript (Node.js) | Get the screenshot as Base64, then write it with Node’s filesystem API. | Decode or write the returned data using the binding’s documented encoding. |
Refer to Selenium’s working with windows and tabs documentation for the binding examples. Do not copy the Python call unchanged into another language.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →What part of the page is captured?
The ordinary Python operation captures the current browser window in the current browsing context. It does not promise a full-page image. The Java API describes screenshots for a WebDriver or an HTML element and notes that behavior can depend on the browser and whether the implementation conforms to the WebDriver standard.
Current window versus full page
A viewport screenshot contains what is visible in the active window at capture time. Content below the fold may be absent. Full-page support varies by browser, driver, Selenium binding, and Selenium version; verify the semantics of the method you plan to use rather than assuming that a normal screenshot stitches the entire document.
Element screenshots
Where the binding and driver support element capture, locate the element first and invoke that binding’s element screenshot method. The Java TakesScreenshot contract includes an HTML element as a possible screenshot source, but exact cropping and support remain implementation-dependent.
Choose the correct window and state
Switch to the intended tab or window before taking the image. Navigate to the target URL, wait for the page state your test requires, and scroll or dismiss overlays if they would otherwise appear in the captured viewport. A screenshot records the state at the instant the command runs.
Rank #3
Reliable destination paths
- Create directories first: call
mkdir(..., exist_ok=True)in Python or the equivalent directory-creation API in your language. - Use unique names in parallel tests: include a test name, browser, timestamp, or worker identifier to prevent one run overwriting another.
- Keep the extension consistent: Python’s file-saving methods are documented for PNG and should receive a filename ending in
.png. - Confirm permissions: containers and CI runners often run as a user that cannot write to application directories. Use a workspace or artifact directory with write access.
- Preserve failures: save screenshots in an error handler before quitting the driver, but still check whether the save succeeded.
Troubleshooting: symptoms and fixes
“No such file or directory”
The parent directory does not exist, or a relative path resolves somewhere unexpected. Create the directory and log the absolute destination. In Python, use Path(path).parent.mkdir(parents=True, exist_ok=True).
The method returns false
Python reports an I/O failure through a false return value. Check the path spelling, filesystem permissions, available disk space, and whether another process has made the destination unavailable. Raise an exception so the test or job fails visibly.
Permission denied in CI or a container
The WebDriver process may run as a restricted account. Point the screenshot directory at the job workspace, mounted artifact directory, or another location writable by that account. Avoid assuming that the directory writable on a developer laptop is writable in CI.
The image is blank or shows the wrong tab
Confirm that the driver is attached to the intended window handle and that navigation has completed. Switch windows explicitly, wait for the page condition you need, and capture after the relevant element is present. The screenshot command does not select a tab for you.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →The screenshot is only the viewport
That is expected for the ordinary current-window call. Check your binding, browser, driver, and Selenium version for a supported full-page or element-specific operation. Do not label a viewport image as a full-page capture.
Java’s file disappears
OutputType.FILE is temporary and may be deleted when the JVM exits. Copy it to the final path immediately, before calling quit() or allowing the process to terminate.
Rank #4
Performance, reliability, and storage considerations
Screenshot capture adds an image-encoding and filesystem write to each test. Capture only the checkpoints that help diagnose a failure or document a required state. In parallel suites, unique filenames avoid races; keep the browser and driver lifecycle separate from artifact cleanup so a failed test can still retain its image.
PNG is lossless and is the format documented for Python’s direct save method. It can be large for long pages or high-resolution displays, so apply your CI artifact-retention policy and remove obsolete files after upload. If you need another format, capture according to the binding’s supported API rather than merely changing a filename extension.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Or skip the browser setup
ScreenshotNeo provides a website screenshot API when you need a URL captured without maintaining Selenium, a browser binary, and a driver. One GET request returns a PNG, JPEG, WebP, or PDF. Its cleanup steps accept cookie and consent banners before capture and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and whether it was billed.
Use the API key from your account. The complete parameter reference is in the ScreenshotNeo documentation.
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,
)
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(`ScreenshotNeo returned ${res.status}`);
require('fs').writeFileSync('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo also supports full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets and custom viewports, retina scale, PDF paper and page controls, HTML/CSS rendering, custom JavaScript and CSS, clicks, selector or network-idle waits, request and resource blocking, custom headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen 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. Parameter names used by other screenshot APIs also work, which can simplify migration.
An MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
Recommended Free Tools
FAQ
Does Selenium save screenshots as JPEG by default?
The Python file-saving methods documented here save PNG files. Use a binding or image-processing workflow that explicitly supports another format instead of changing only the filename suffix.
Best Value
Can I save a screenshot after calling driver.quit()?
No. The driver must remain active while Selenium captures the current window. Save the artifact before quitting the driver.
What should I archive from a failed test?
Archive the screenshot together with the test name, browser and driver versions, URL, and relevant logs. Those details make a visual failure reproducible without changing the screenshot API call.
Frequently Asked Questions
Does Selenium save screenshots as JPEG by default?
The Python file-saving methods documented here save PNG files. Use a binding or image-processing workflow that explicitly supports another format instead of changing only the filename suffix.
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 matchCan I save a screenshot after calling driver.quit()?
No. The driver must remain active while Selenium captures the current window. Save the artifact before quitting the driver.
What should I archive from a failed test?
Archive the screenshot together with the test name, browser and driver versions, URL, and relevant logs. Those details make a visual failure reproducible without changing the screenshot API call.
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.

