Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use Selenium’s screenshot method on the WebDriver or on a specific element. In Python, the shortest working example is driver.save_screenshot("screenshot.png"). For a component rather than the whole current browsing context, find it first and call element.screenshot("element.png"). The equivalent operation exists in Selenium’s other language bindings, but each binding returns or saves the image differently.
This guide shows dependable scripts, explains what “current context” means, covers headless execution, and identifies the browser and driver details you must verify before promising full-page output.
What Selenium actually captures
Selenium sends a WebDriver screenshot command to the browser controlling your current window or tab. The documented driver-level operation captures the current browsing context: the page, frame, or window selected at the moment of the call. It is not automatically a screenshot of every tab, every frame, or an arbitrarily long document.
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 →An element screenshot uses the element’s rendered rectangle. It is useful for a heading, chart, product card, test failure region, or any other component that can be located in the DOM.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
- Current context: capture the browser view represented by the active WebDriver context.
- Element: locate one element and save only that element’s image.
- Full page: do not assume the basic call stitches an entire scrolling document in every browser and driver combination. Verify the exact browser, driver, Selenium version, and full-page technique you plan to deploy.
Python: save a browser screenshot
Install Selenium in the environment that will run the test, ensure a compatible browser is available, and let Selenium create a Chrome driver. This example follows the documented flow: start the driver, navigate, save, and quit.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.example.com")
driver.save_screenshot("screenshot.png")
driver.quit()
After the script finishes, screenshot.png is written relative to the process’s working directory. Use an absolute path when a CI job, container, or test runner may start in an unexpected directory.
Make cleanup reliable
If navigation or capture raises an exception, a plain sequence can leave Chrome running. Put the driver in a try/finally block so the browser is closed on both success and failure.
Recommended Free Tools
from pathlib import Path
from selenium import webdriver
output = Path("artifacts/home.png")
output.parent.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
driver.get("https://www.example.com")
if not driver.save_screenshot(str(output)):
raise RuntimeError("Selenium reported that the screenshot was not saved")
finally:
driver.quit()
The return value is a success indicator in Python. Treat a false result as a failed artifact rather than silently continuing.
Python: capture one element
Find the element after the page has loaded, then call its screenshot method. CSS selectors are explicit and easy to review in tests.
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
try:
driver.get("https://www.example.com")
heading = driver.find_element(By.CSS_SELECTOR, "h1")
heading.screenshot("heading.png")
finally:
driver.quit()
The element must exist and be rendered in the current context. If it is inside an iframe, switch into that frame first; if it is in another window, switch to that window before locating it.
Wait for a rendered target
Dynamic pages often add the target after the initial navigation response. An explicit wait avoids capturing a missing, hidden, or half-populated component.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
try:
driver.get("https://www.example.com")
heading = WebDriverWait(driver, 15).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "h1"))
)
heading.screenshot("heading.png")
finally:
driver.quit()
Choose a condition that matches the artifact you need. Presence proves that a node exists; visibility is a better minimum for an image intended for a person or visual test.
Other Selenium language bindings
The WebDriver endpoint returns Base64-encoded image data. Bindings expose that data through language-specific methods, so the same conceptual operation has different syntax and file handling.
Java
import java.io.File;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.io.FileHandler;
WebDriver driver = new ChromeDriver();
try {
driver.get("https://www.example.com");
File image = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileHandler.copy(image, new File("screenshot.png"));
} finally {
driver.quit();
}
Java obtains a temporary file through TakesScreenshot and copies it to the destination you choose.
JavaScript (Node.js)
const fs = require('node:fs/promises');
const { Builder } = require('selenium-webdriver');
const driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get('https://www.example.com');
const base64 = await driver.takeScreenshot();
await fs.writeFile('screenshot.png', base64, 'base64');
} finally {
await driver.quit();
}
The documented JavaScript method returns Base64 data; write it with the Base64 encoding rather than treating it as ordinary text.
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 minuteC#
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
IWebDriver driver = new ChromeDriver();
try
{
driver.Navigate().GoToUrl("https://www.example.com");
Screenshot shot = ((ITakesScreenshot)driver).GetScreenshot();
shot.SaveAsFile("screenshot.png");
}
finally
{
driver.Quit();
}
Ruby and Kotlin
Ruby and Kotlin bindings also provide screenshot methods that save to a path or file. Follow the binding’s current API for the exact method signature and output type; do not copy Python’s return-value assumptions into another language.
Headless Chrome: when to use it
Selenium’s official JavaScript example configures Chrome with the --headless argument and then captures a screenshot. Headless mode is therefore a documented option, not a universal requirement for ordinary screenshots. A visible browser is often preferable while developing because you can inspect layout, redirects, consent dialogs, and authentication interactively.
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const options = new chrome.Options().addArguments('--headless');
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
try {
await driver.get('https://www.example.com');
await driver.takeScreenshot();
} finally {
await driver.quit();
}
Do not transfer Selenium’s separate PDF guidance to image capture: the documented headless requirement applies to Chromium page-to-PDF, not automatically to screenshots.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Frames, windows and timing
Frames
A locator searches the current document. For an element inside an iframe, switch first:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsfrom selenium.webdriver.common.by import By
frame = driver.find_element(By.CSS_SELECTOR, "iframe")
driver.switch_to.frame(frame)
inner = driver.find_element(By.CSS_SELECTOR, "h1")
inner.screenshot("inside-frame.png")
driver.switch_to.default_content()
Windows and tabs
Use driver.switch_to.window(handle) before capture when a click opened a new tab. The screenshot applies to whichever window is active, not necessarily the first one created.
Animations and lazy content
Wait for a stable state before saving. A screenshot can legitimately contain an animation frame, a loading skeleton, or an image that has not yet loaded. In a visual test, disable or freeze animations with test CSS, wait for a meaningful selector, and ensure lazy content has entered the viewport.
Full-page expectations and verification
The basic driver call is documented for the current browsing context, while the element call is documented for a selected element. Browser and driver implementations differ on viewport and full-page behavior. Before relying on a tall image, verify:
- the browser family and exact version;
- the matching driver and Selenium version;
- whether the chosen endpoint captures only the viewport or supports the full document;
- how fixed headers, sticky elements, overflowing containers, and lazy images are handled; and
- the maximum image dimensions accepted by your storage or test system.
If a complete page is a hard requirement, test the exact production combination rather than assuming that a call which works in one browser will stitch pages identically in another.
Reliable automation patterns
Use deterministic artifact paths
Include a test name, browser, and timestamp or run identifier in the filename. Create the directory before capture and preserve the artifact when a test fails.
Control viewport deliberately
Responsive layouts change with viewport size. Set the window or browser options explicitly in your test setup and record that choice with the artifact. Retina or device-pixel scaling can change the image’s pixel dimensions even when CSS dimensions are unchanged.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Capture after the assertion state
For failure diagnostics, take the screenshot in the exception path, before quitting the driver. For golden-image tests, capture only after all required network requests and UI transitions have completed.
Keep secrets out of artifacts
Screenshots may contain account names, tokens displayed by an application, customer data, or private URLs. Store them with the same access controls as logs, and mask sensitive fields in the application or with test CSS before capture.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Troubleshooting Selenium screenshots
“Unable to obtain driver” or browser startup failure
Install a supported browser and ensure Selenium can obtain or find its driver. Check browser/driver compatibility, executable permissions, container dependencies, and the process PATH. Run a minimal navigation test before debugging image code.
The file is missing or empty
Use an absolute path, create its parent directory, check the Python boolean return value or the other binding’s exception, and confirm the process can write to that location. A container may be writing inside its own filesystem rather than your host workspace.
The element cannot be located
Verify the selector in the active document, wait for it, switch into the correct iframe, and switch to the correct window. A selector copied from a transient class name may stop working after a frontend deployment.
The screenshot shows a loading state
Navigation completion does not guarantee that client-rendered data or images are ready. Wait for a visible, application-specific completion condition; avoid relying only on a fixed sleep, which is either flaky or unnecessarily slow.
The image is clipped or not full page
That may be normal for the browser/driver combination. Confirm the documented scope of the endpoint and test a full-page-capable method for your exact versions. Inspect scrollable containers separately when the content is not part of the document viewport.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Headless output differs from headed output
Compare viewport dimensions, device scale, fonts, GPU settings, animation timing, and page load timing. Capture both modes during diagnosis; do not assume that headless and visible Chrome render identical pixels.
Performance, reliability and cost considerations
Each capture requires browser work, image encoding, and disk or network I/O. Reuse a driver for related pages when isolation permits, but create a fresh session when cookies, local storage, permissions, or test state could contaminate the next artifact. Parallel browsers increase throughput while also increasing CPU, memory, and renderer pressure.
Selenium itself does not charge per screenshot; your costs are the machines, browser sessions, storage, and CI minutes that run them. Keep only the artifacts you need, compress or resize them downstream when pixel-perfect output is unnecessary, and avoid capturing on every polling attempt.
Or skip the browser setup
ScreenshotNeo provides a website screenshot API when you want one request instead of managing WebDriver. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers.
For a direct image request, see the ScreenshotNeo documentation:
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 call 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)
open("shot.webp", "wb").write(r.content)
And 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 also offers an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Its 63 options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper settings and page ranges, HTML/CSS rendering, custom JavaScript and CSS, pre-capture clicks, selector hiding, selector/delay/network-idle waits, request and resource blocking, headers, cookies, user agents, Authorization, timezone, geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, an OpenAPI specification, and compatible parameter names used by other screenshot APIs.
The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 screenshots; yearly billing provides two months free, and every feature is on every plan. Create a free ScreenshotNeo account to try it.
Frequently Asked Questions
Does Selenium save PNG, JPEG, or WebP by default?
The documented Selenium screenshot examples save an image through the binding’s file or Base64 handling, with PNG used in the Python examples. Choose a conversion step outside Selenium when your workflow requires another format.
Can I screenshot an iframe without switching into it?
No. Selenium locators operate in the active document, so switch to the iframe before locating an inner element, then return to the default content when finished.
Is a fixed sleep enough to make screenshots stable?
A fixed delay can help with a known animation but does not prove that application data or images are ready. An explicit wait for the state you need is generally more reliable.
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.
Free tools Windows power users keep installed
One-click scans. No signup required.

