Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
The standard Selenium Python syntax is driver.save_screenshot("shot.png"). It captures the current browser window as a PNG and returns True when Selenium writes the file successfully or False when an I/O error prevents the write. Use get_screenshot_as_png() for PNG bytes, get_screenshot_as_base64() for text suitable for HTML, element.screenshot() for one element, and Firefox’s get_full_page_screenshot_as_file() when you need a documented full-document capture.
What Selenium screenshot methods actually capture
Screenshot behavior depends on both the method and the target. Driver-level methods capture the current browser window; an element method captures only the selected element; Firefox exposes a separate full-page method. Treat these as different operations rather than assuming every browser produces a complete, scrollable-page image.
| Need | Python syntax | Result | Important qualification |
|---|---|---|---|
| Current window to disk | driver.save_screenshot("shot.png") |
PNG file and Boolean | Use a writable path ending in .png. |
| Equivalent file method | driver.get_screenshot_as_file("shot.png") |
PNG file and Boolean | The Python implementation delegates save_screenshot to this method. |
| PNG in memory | driver.get_screenshot_as_png() |
PNG bytes | Useful when another library will store or process the image. |
| Base64 in memory | driver.get_screenshot_as_base64() |
Base64 text | Useful for embedding in HTML or transporting as text. |
| One element | element.screenshot("element.png") |
Element PNG | Find the element first; this is not a whole-window capture. |
| Full document in Firefox | driver.get_full_page_screenshot_as_file("full-page.png") |
Full-page PNG file | Documented by Firefox; do not assume identical support in every driver. |
Save the current window as a PNG
Install Selenium and ensure a compatible browser and WebDriver are available. This complete example opens a page, writes the screenshot into a directory, and treats a failed Boolean result as an error.
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 →from pathlib import Path
from selenium import webdriver
output = Path("screenshots")
output.mkdir(parents=True, exist_ok=True)
with webdriver.Chrome() as driver:
driver.get("https://example.com")
ok = driver.save_screenshot(str(output / "home.png"))
if not ok:
raise OSError("Screenshot could not be written")
save_screenshot means “save a screenshot of the current window to a PNG image file.” It does not wait for a page to become visually complete. Navigate first, then add your own wait for a condition when the page renders asynchronously.
#1 Best Overall
The equivalent method
ok = driver.get_screenshot_as_file("screenshots/home.png")
if not ok:
raise OSError("Screenshot could not be written")
Both methods return a Boolean. Check it rather than assuming that a call succeeded. A missing directory, permission problem, read-only filesystem, or other file I/O failure can produce False.
Why the extension and path matter
- Use a path whose filename ends in
.png, as documented by the Selenium Python API. - Create the parent directory before capture; Selenium does not create missing directories for you.
- Use an absolute path when a test runner, container, or CI job has an unexpected working directory.
- Give each test a unique filename if parallel workers could overwrite one another.
Get PNG bytes or base64 instead of writing a file
In-memory methods avoid an intermediate file and let your application decide how to store, transform, upload, or embed the result.
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("home.png", "wb") as image_file:
image_file.write(png_bytes)
get_screenshot_as_png() returns the PNG payload as Python bytes. Open the destination in binary mode (wb), or pass the bytes directly to an image processor, object-storage client, test attachment API, or HTTP request.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #2
Base64 for HTML
from selenium import webdriver
with webdriver.Chrome() as driver:
driver.get("https://example.com")
encoded = driver.get_screenshot_as_base64()
html = f'<img alt="Page capture" src="data:image/png;base64,{encoded}">'
with open("report.html", "w", encoding="utf-8") as report:
report.write(html)
Base64 is text, not a PNG file. Selenium documents this encoding as useful for embedding screenshots in HTML. Add the data:image/png;base64, prefix when constructing a data URL.
Capture one element rather than the browser window
Use an element screenshot when a test needs a card, chart, logo, form, or other component. The Python binding’s syntax is:
from selenium import webdriver
with webdriver.Chrome() as driver:
driver.get("https://example.com")
element = driver.find_element("css selector", "main")
ok = element.screenshot("main.png")
if not ok:
raise OSError("Element screenshot could not be written")
The selector can target any element your page exposes. Element capture is distinct from driver-level capture: it does not intentionally represent the complete browser viewport. If the target is hidden, detached, outside a usable layout, or still changing, wait for the page state your test requires before calling screenshot.
Rank #3
Full-page screenshots and browser differences
A normal save_screenshot or get_screenshot_as_file call is documented as a current-window capture. A long page may therefore produce only the visible viewport, depending on the browser driver. Firefox documents a dedicated full-document method:
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 & 11Crashes, 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 minutefrom pathlib import Path
from selenium import webdriver
Path("screenshots").mkdir(exist_ok=True)
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 could not be written")
Keep the distinction explicit in cross-browser tests. If your requirement is “what the user currently sees,” use the regular driver method. If it is “the entire document in one image,” select a browser and driver combination that documents full-page support, or use a service designed for that job.
Make captures deterministic
Wait for the state you intend to record
driver.get() returns after navigation reaches the browser’s normal load milestone, but JavaScript applications can continue rendering. Wait for a specific element, text, or application condition rather than relying on a fixed sleep wherever possible. A capture taken before fonts, images, or data arrive can be valid PNG output and still be the wrong evidence.
Rank #4
Control layout inputs
- Set a known window size when pixel dimensions matter.
- Use the same browser, operating-system scale factor, and fonts in visual-regression runs.
- Dismiss overlays or close menus that are not part of the state under test.
- Use stable test data and freeze animations where your application permits it.
Choose a filename strategy
Include a test name, viewport, and timestamp or build identifier in the path. Keep the extension .png; convert formats after capture if your downstream workflow needs JPEG or WebP.
Troubleshooting Selenium screenshot failures
| Symptom | Likely cause | Fix |
|---|---|---|
Method returns False |
File I/O error | Verify the directory exists, the path is writable, the process has permission, and the filename ends in .png. Log the absolute path. |
FileNotFoundError from your own write |
Parent directory was never created | Call Path(...).mkdir(parents=True, exist_ok=True) before saving. |
| Image shows only the viewport | Regular driver capture is a current-window operation | Use Firefox’s documented full-page method where appropriate, or capture sections separately. |
| Element screenshot fails or is blank | Wrong selector, hidden element, detached node, or unfinished layout | Locate the element after navigation, wait for it to be visible and stable, then capture it. |
| Screenshot is visually incomplete | Asynchronous content, lazy images, fonts, or animations were still loading | Wait on a meaningful readiness condition and disable test-only motion where possible. |
| Works locally but not in CI | Different working directory, permissions, display mode, browser, or fonts | Use absolute output paths, create directories, record browser/driver versions, and standardize the execution image. |
| Parallel tests overwrite images | Shared static filename | Generate unique names per test and worker. |
Or skip the browser setup
ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF, while options cover full-page captures, element selectors, device and viewport settings, retina scale, custom CSS and JavaScript, clicks, waits, blocked resources, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, caching, signed links, asynchronous webhooks, bulk capture, usage reporting, and PDF controls. It also accepts the parameter names used by other screenshot APIs, which can simplify a migration.
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 →Before capture, it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup 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 billing status. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
See the ScreenshotNeo API documentation for the full parameter reference. This cURL request saves a WebP capture:
Best Value
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(`HTTP ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo’s Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; every feature is on every plan. Create a free ScreenshotNeo account to get the monthly allowance.
Cost, performance, and reliability choices
Local Selenium
Local capture gives you direct control over the browser, test data, authentication state, and in-memory output. It also makes you responsible for browser installation, driver compatibility, fonts, filesystem permissions, page waits, and the behavior of each browser’s full-page implementation.
An API workflow
An API avoids maintaining a browser process in every caller and can return a ready image or PDF from one request. Account for network latency, authentication, request timeouts, remote-page access, and the service’s billing rules. ScreenshotNeo reports whether a response was billed and does not bill the listed failed-load, bot-check, blank-page, timeout, or cache-hit cases.
Reduce unnecessary work
- Capture only the viewport or element required by the test.
- Reuse a browser session when several pages share setup, while isolating tests that need clean state.
- Use bytes when you will upload immediately; avoid writing and rereading a temporary file.
- Use caching or asynchronous jobs for repeated or high-volume API captures.
Quick decision checklist
- Current viewport:
save_screenshot. - Equivalent file API:
get_screenshot_as_file. - Programmatic processing:
get_screenshot_as_png. - HTML embedding:
get_screenshot_as_base64. - One component:
element.screenshot. - Document-wide Firefox capture:
get_full_page_screenshot_as_file. - No browser installation or agent-friendly capture: ScreenshotNeo’s API or MCP server.
Frequently Asked Questions
Does Selenium save screenshots as JPEG by default?
No. The documented Python file methods save PNG screenshots. Convert the resulting image afterward if another format is required.
Can I use the same full-page method in every browser?
Do not assume that. The documented full-page method in the supplied API material is Firefox-specific; ordinary driver methods describe the current window.
What is the difference between base64 and PNG bytes?
PNG bytes are binary image data for storage or processing; base64 is text, commonly placed in a data URL for HTML.
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.

