Recommended Free Tools
In Python, call driver.save_screenshot("screenshot.png") while the WebDriver session is open. The method captures the current window, writes a PNG, and returns False if saving encounters an I/O error. Use an explicit, writable path and check that return value. Java uses the equivalent TakesScreenshot.getScreenshotAs(OutputType...) API.
This guide shows reliable file, byte, Base64, and element captures; explains what “current window” means; and provides fixes for the failures that commonly appear in CI.
Python: save the current window as a PNG
The following is a complete test-friendly example. It creates the artifact directory, opens a page, saves the screenshot, checks Selenium’s Boolean result, and always closes the browser.
from pathlib import Path
from selenium import webdriver
output = Path("artifacts") / "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"Could not save screenshot to {output}")
print(f"Screenshot written to {output.resolve()}")
finally:
driver.quit()
Use a .png suffix. A relative path is resolved from the process’s working directory, which may differ between your laptop, an IDE, and a CI runner; an absolute path or a path built from a known artifact directory is safer. The Python WebDriver API describes save_screenshot(filename) as saving the current window to a PNG and returning False on an I/O error.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Capture image data without writing a file
PNG bytes
get_screenshot_as_png() returns binary PNG data. This is useful when an HTTP client, object-storage SDK, test-reporting library, or image-processing package accepts bytes directly.
png_bytes = driver.get_screenshot_as_png()
with open("artifacts/in-memory-copy.png", "wb") as image_file:
image_file.write(png_bytes)
Base64
get_screenshot_as_base64() returns a Base64-encoded string. It is convenient for embedding an image in an HTML report or constructing a data URL.
import base64
encoded = driver.get_screenshot_as_base64()
data_url = "data:image/png;base64," + encoded
# Example: place data_url in an HTML img src attribute.
Choose one representation for each workflow: a saved file for CI artifacts, bytes for uploads or image assertions, and Base64 for self-contained HTML reports.
Java: use TakesScreenshot
Java exposes screenshots through the TakesScreenshot interface. The official pattern asks for a temporary file and copies it to the destination you control.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import 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 Capture {
public static void main(String[] args) throws IOException {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
File source = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
File destination = new File("artifacts/page.png");
FileUtils.forceMkdirParent(destination);
FileUtils.copyFile(source, destination);
} finally {
driver.quit();
}
}
}
This example requires Apache Commons IO for FileUtils. Selenium also supports other output types, including Base64, through getScreenshotAs(OutputType...). The cast is valid only when the active driver implements TakesScreenshot. Unsupported implementations can raise UnsupportedOperationException; a driver or browser that cannot complete the command can raise a WebDriver-related exception.
Capture one element instead of the window
When the evidence you need is a component—such as a failed form, chart, or logged-in account panel—use the element screenshot API where your binding and browser support it.
from selenium import webdriver
with webdriver.Chrome() as driver:
driver.get("https://example.com")
panel = driver.find_element("css selector", "main")
if not panel.screenshot("artifacts/main.png"):
raise OSError("Element screenshot could not be saved")
Selenium’s documentation also shows element.screenshot(...) in Python, and Java’s API includes WebElement in the screenshot interface hierarchy. Element capture avoids unrelated browser chrome and page regions, but support and rendering details still depend on the browser/driver combination.
What Selenium actually captures
The ordinary WebDriver screenshot operation targets the current browsing context (often described in Python as the current window). It is not a universal promise of a full, scrollable-document image. A long page may produce an image of the visible viewport or browser-defined window area rather than every pixel below the fold.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Before capturing
- Navigate to the intended URL and wait for the state you want to document.
- Switch to the correct tab or window with
driver.switch_to.window(handle). - Switch into the correct iframe before locating an element inside it.
- Dismiss test-only overlays or wait for a selector that proves the page is ready.
If you need a full document, do not assume that a generic recipe works across browsers. Full-page behavior is browser-, driver-, and binding-dependent; verify the current official documentation for your exact combination or use a browser-specific method deliberately.
A practical capture pattern for failed tests
Put screenshot handling in the failure path so successful tests do not create unnecessary files. Keep the driver alive until after the capture, and include a unique test identifier in the filename.
from pathlib import Path
from datetime import datetime
from selenium import webdriver
artifacts = Path("artifacts")
artifacts.mkdir(exist_ok=True)
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
# test steps go here
except Exception:
stamp = datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")
path = artifacts / f"failure-{stamp}.png"
if not driver.save_screenshot(str(path)):
print(f"Screenshot save failed: {path}")
raise
finally:
driver.quit()
In a test framework, attach the resulting file to the framework’s report rather than printing large Base64 strings into logs. If several tests run in parallel, use a test name plus a worker or UUID component to prevent files overwriting one another.
Common errors and precise fixes
| Symptom | Likely cause | Fix |
|---|---|---|
save_screenshot returns False |
The destination cannot be written, the directory is missing, or the process lacks permission. | Create the parent directory, use an absolute path under the CI artifact directory, verify permissions, and check the Boolean result. |
| The file is not where expected | A relative path is based on the test process’s working directory, not necessarily the project directory. | Log Path(path).resolve() or use a configured absolute artifact path. |
| Wrong page or tab appears | The driver is on another window, tab, frame, or earlier navigation state. | Switch to the intended window, switch into the required iframe, and wait for a page-specific condition before capture. |
| Only part of a long page is visible | The generic command captures the current browsing context; full-document capture is not universal. | Use an element capture or a browser-specific full-page technique after checking support for your exact driver. |
WebDriverException or unsupported-operation error |
The session has ended, the driver is not conformant, or screenshot capture is unsupported. | Capture before quit(), inspect the original driver error, update compatible browser/driver components, and test the command in isolation. |
| Blank or stale image | The page is still loading, an animation has not settled, or the requested element is outside the intended state. | Wait for a reliable element or application condition rather than an arbitrary short sleep; disable or account for animations when deterministic visuals matter. |
| Parallel tests overwrite evidence | Every test uses the same filename. | Include the test name, timestamp, and worker/run identifier in each path. |
Reliability, speed, and storage considerations
Wait for state, not time
A screenshot is only useful if it represents the state under investigation. Prefer explicit waits for a visible element, a URL change, or an application-ready marker. A fixed delay can be too short on a busy runner and needlessly slow on a fast one.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Control artifact volume
PNG is lossless and easy to inspect, but repeated captures can consume substantial CI storage. Capture on failure, at key checkpoints, or when a visual assertion requires it. Retain only the number of runs your team needs and apply your CI system’s artifact retention policy.
Account for browser differences
Viewport size, device scale factor, fonts, operating-system rendering, browser version, and driver implementation can change pixels. If screenshots are compared visually, standardize those inputs and record them with the artifact. The Java API notes that non-conformant implementations may be best-effort and browser-dependent; do not treat an identical result as guaranteed across environments.
Protect sensitive data
Screenshots can contain account names, tokens, addresses, or customer data. Mask or remove sensitive fields before capture when possible, restrict artifact access, and set an appropriate retention period.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
For a direct URL-to-image request, ScreenshotNeo provides a website screenshot API and MCP server. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing result.
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 minuteSee the ScreenshotNeo documentation for all options. A one-call example is:
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request in 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)
And in 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 failed: ${res.status}`);
const buffer = Buffer.from(await res.arrayBuffer());
require('fs').writeFileSync('shot.webp', buffer);
ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Its 1,000-shot monthly Free plan requires no card; paid plans start at $5 for 3,000 shots, and every feature is on every plan. If you want URL capture without maintaining a browser session, create a free ScreenshotNeo account.
Which Selenium output should you choose?
| Need | Recommended API | Result |
|---|---|---|
| Attach an artifact to CI | save_screenshot(path) |
PNG file and a success Boolean |
| Upload or inspect pixels in code | get_screenshot_as_png() |
PNG bytes |
| Embed in an HTML report | get_screenshot_as_base64() |
Base64 string |
| Document one component | element.screenshot(path) |
Element image where supported |
| Use Java | TakesScreenshot.getScreenshotAs(OutputType...) |
File, Base64, or another supported representation |
Frequently Asked Questions
Does Selenium take a screenshot before or after an assertion fails?
It captures whatever state exists when the command runs. Put the call inside your exception or test-framework failure hook, before the driver is closed.
Can I save a Selenium screenshot as JPEG?
The documented Python save method writes PNG. If you need another format, obtain PNG bytes and convert them with an image library after capture.
Free tools Windows power users keep installed
One-click scans. No signup required.
Why should I check the Python return value?
A successful WebDriver command does not guarantee that the local file write succeeded. Selenium returns False for an I/O error, allowing your test or reporting hook to surface the failure.
Is a screenshot command safe after driver.quit()?
No. The session is closed at that point. Capture first, then call quit in cleanup.
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.

