In Selenium’s Python API, capture the current browser viewport with driver.save_screenshot("path.png"), capture one element with element.screenshot("path.png"), or keep the image in memory with driver.get_screenshot_as_png(). Firefox also exposes full-document screenshot methods. Always use a writable path ending in .png, wait until the page state you want is ready, and check the Boolean returned by file-saving methods.
Choose the screenshot scope first
A Selenium screenshot can represent three different things. Selecting the scope before writing code prevents the common mistake of expecting a viewport capture to contain content below the fold.
| Goal | Python API | Result |
|---|---|---|
| Visible browser area | driver.save_screenshot(path) or driver.get_screenshot_as_file(path) |
PNG file of the current window viewport |
| One DOM element | element.screenshot(path) |
PNG file clipped to that element |
| Image without a file | driver.get_screenshot_as_png() or driver.get_screenshot_as_base64() |
PNG bytes or base64 text |
| Entire document | Firefox’s get_full_page_screenshot_as_file or save_full_page_screenshot |
PNG of the full page, where the Firefox driver supports the method |
Viewport screenshots use the current window dimensions. If pixel dimensions matter, set them explicitly before loading or capturing the page.
Set up a repeatable Python capture
Install Selenium and prepare an output directory
Install Selenium in the environment that will run the test or capture job:
Recommended Free Tools
#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.
python -m pip install selenium
Your machine or CI runner also needs a supported browser and a compatible WebDriver configuration. The example below uses Chrome, creates the output directory, fixes the viewport at 1,280 by 900 pixels, and closes the browser even when navigation or writing fails.
from pathlib import Path
from selenium import webdriver
out = Path("screenshots")
out.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
driver.set_window_size(1280, 900)
driver.get("https://example.com")
# Wait for the application-specific ready state here.
ok = driver.save_screenshot(str(out / "home.png"))
if not ok:
raise OSError("Selenium could not write the screenshot")
finally:
driver.quit()
save_screenshot and get_screenshot_as_file perform the same kind of PNG file capture and return a Boolean. Treat False as a failed artifact rather than assuming that a file exists.
Capture the current viewport
Save a PNG to disk
from selenium import webdriver
with webdriver.Chrome() as driver:
driver.set_window_size(1440, 900)
driver.get("https://example.com")
if not driver.get_screenshot_as_file("screenshots/viewport.png"):
raise OSError("Screenshot write failed")
Use a full path in production jobs when the working directory is not controlled. The filename should end in .png; Selenium’s Python implementation warns about a different extension and reports operating-system write errors as False.
Control what is visible
Resize the window before the screenshot, not after it. A responsive page may choose a different layout at another width, so a fixed width and height make visual regression artifacts comparable between runs. The screenshot reflects the state that is visible at the instant of capture; it does not automatically wait for a framework, image, animation, or API request to finish.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Wait for the page state you intend to document
There is no universal “page is ready for screenshots” condition. Define one for your application and wait for it before calling a screenshot method. Typical choices include a known heading becoming visible, a loading spinner disappearing, or a page-specific network completion signal exposed by the application.
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.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
with webdriver.Chrome() as driver:
driver.set_window_size(1280, 900)
driver.get("https://example.com/dashboard")
WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "main.dashboard"))
)
if not driver.save_screenshot("screenshots/dashboard.png"):
raise OSError("Screenshot write failed")
If the page contains lazy-loaded images, scroll or otherwise trigger the application’s loading behavior before capture. Waiting for a selector only proves that selector’s condition; it does not prove that every visual asset on the page is complete.
Screenshot one Selenium element
Use a WebElement screenshot when the artifact should contain a card, chart, form, or other DOM node rather than the whole viewport.
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
out = Path("screenshots")
out.mkdir(exist_ok=True)
with webdriver.Chrome() as driver:
driver.get("https://example.com")
element = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
)
if not element.screenshot(str(out / "main.png")):
raise OSError("Element screenshot write failed")
The element API also provides element.screenshot_as_png and element.screenshot_as_base64. These forms avoid writing a file and are useful when a test uploads bytes directly or embeds the image in another report.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →The element must be present and rendered. A selector that matches a hidden template, a zero-size node, or an element covered by an application state may produce an unusable result; wait for the visible state that your test actually intends to record.
Keep the screenshot in memory
PNG bytes
from selenium import webdriver
with webdriver.Chrome() as driver:
driver.get("https://example.com")
png_bytes = driver.get_screenshot_as_png()
with open("screenshots/in-memory.png", "wb") as image_file:
image_file.write(png_bytes)
get_screenshot_as_png() returns binary PNG data. It is the appropriate form for an object-storage upload, an image-processing pipeline, or a test attachment API that accepts bytes.
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.
Base64 for HTML
from selenium import webdriver
with webdriver.Chrome() as driver:
driver.get("https://example.com")
image_base64 = driver.get_screenshot_as_base64()
html = f'
'
with open("screenshots/report.html", "w", encoding="utf-8") as report:
report.write(html)
The base64 representation is text and is suitable for embedding in HTML. Do not confuse it with PNG bytes: writing base64 text to a binary image file will not create a valid PNG.
Capture a full document with Firefox
A normal WebDriver screenshot is a viewport image. Firefox’s Python WebDriver API additionally documents full-document methods:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
from selenium import webdriver
with webdriver.Firefox() as driver:
driver.get("https://example.com/long-page")
ok = driver.get_full_page_screenshot_as_file(
"screenshots/full-page.png"
)
if not ok:
raise OSError("Full-page screenshot write failed")
The Firefox driver also exposes save_full_page_screenshot and PNG/base64 variants. These names are Firefox-specific in the cited API; do not assume that the same full-document method exists on every browser driver. If portability across Chrome, Firefox, and remote drivers is a requirement, test the exact driver/version combination used by your pipeline and consider stitching viewport captures as an application-level fallback.
Make captures reliable in CI
Use deterministic inputs
- Set the window width and height explicitly.
- Use a stable test account and fixed seed data where the page content is data-dependent.
- Wait for a page-specific ready condition instead of relying on a fixed sleep alone.
- Capture after navigation, modal dismissal, or other interaction that defines the state under test.
Check every artifact
File-saving methods return True or False. Raise an error, mark the test failed, or retry according to your artifact policy when the result is False. Also verify that the destination directory exists and that the process has write permission.
Protect sensitive output
Screenshots can contain passwords, session identifiers, personal information, customer records, or test secrets visible in the browser. Apply the same retention, access-control, and redaction rules used for logs and video. Avoid publishing raw artifacts from authenticated environments.
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
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
Method returns False |
Bad path, missing directory, wrong permissions, or an operating-system write error | Create the directory, use a writable full path ending in .png, and check the Boolean. |
| Screenshot shows a loading shell | Capture occurred before the application rendered its real state | Wait for a meaningful application selector or completion signal. |
| Only the visible top portion is present | A normal window screenshot captures the viewport, not the full document | Use Firefox full-document methods where supported, or implement a tested scrolling/stitching strategy. |
| Element capture raises an element/visibility error | The selector matched nothing, a hidden node, or a zero-size element | Wait for visibility, confirm the selector, and capture the rendered instance rather than a template node. |
| Images or fonts are missing | Resources were still loading or were blocked in the test environment | Wait for the application’s visual-ready condition and diagnose network or browser-policy failures separately. |
| Different runs have different layouts | Window dimensions or responsive breakpoints changed | Call set_window_size(width, height) before capture and keep browser configuration consistent. |
| Base64 output cannot be opened as an image | Text was treated as binary PNG data | Use get_screenshot_as_png() for binary files, or embed the base64 value in a data:image/png;base64,... URL. |
Performance, storage, and cost considerations
Viewport and element captures usually require less image data than a long full-document image. Full-page artifacts can be very tall and consume more memory, transfer bandwidth, and storage. Keep the scope as small as the test question allows, use in-memory bytes when a file is unnecessary, and delete temporary artifacts after uploading them to the test report.
For large suites, avoid launching a new browser for every independent image when the test design permits reuse; still isolate tests that depend on clean browser state. Name files with the test case, viewport, and build identifier so parallel workers do not overwrite one another. A screenshot is evidence of one browser state, not proof that every viewport or browser behaves identically; pair visual captures with functional assertions.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
ScreenshotNeo provides a website screenshot API and MCP server for developers. A single GET request returns PNG, JPEG, WebP, or PDF. It accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result.
Use the ScreenshotNeo documentation for all parameters. The same endpoint can also capture full pages, one CSS-selected element, dark mode, custom viewport and retina scale, PDF ranges and margins, HTML/CSS, custom JavaScript, clicks, selector waits, network-idle waits, blocked requests, headers, cookies, user agents, Authorization, timezone, geolocation, transparent backgrounds, resizing, TTL-based caching, signed image links, asynchronous webhooks, bulk requests for up to 100 URLs, usage data, and OpenAPI integration. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
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(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
Every ScreenshotNeo plan includes every feature. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots, followed by Growth at $15 for 15,000, Pro at $39 for 60,000, Scale at $99 for 250,000, and Business at $249 for 1,000,000. Yearly billing provides two months free. Create a free ScreenshotNeo account to start without a card.
Frequently asked questions
Can Selenium save JPEG or WebP directly?
The documented Selenium methods in this workflow save PNG files or return PNG data. Convert the PNG afterward with an image-processing library if another format is required.
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.
Should I use a fixed sleep before every screenshot?
No. A fixed delay may be too short on a busy runner and unnecessarily slow on a fast one. Prefer an explicit condition that represents the application state you need to document, adding a bounded timeout.
Can I use an element screenshot for content outside the viewport?
An element screenshot targets the WebElement, but browser-driver behavior for off-screen or unusually large elements can vary. Scroll the element into a rendered state and validate the output with the driver/browser combination used in your project.
Why is my full-page Firefox image different from a viewport image?
They represent different capture scopes. A viewport image records the current window; a full-document method includes the page beyond the fold and may expose layout or lazy-loading behavior that is not visible in the viewport.
Free tools Windows power users keep installed
One-click scans. No signup required.
Frequently Asked Questions
What file extension should I use with Selenium’s file screenshot methods?
Use a writable filename ending in .png; check the returned Boolean and treat False as a write failure.
Which Selenium value should I send to an HTML report?
Use get_screenshot_as_base64() and place it in a data:image/png;base64,... image URL.
Quick Recap
Which API is simplest when I do not want to manage a browser?
ScreenshotNeo’s GET endpoint captures a URL without Selenium setup, removes common consent banners, popups, and chat widgets, and does not bill failed loads or bot checks.
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.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors

