Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium WebDriver to open the page, call driver.save_screenshot(), verify its Boolean result, and close the driver in a finally block. The Python example below saves a dependable PNG; later sections show element captures, Firefox full-document captures, in-memory output, waits for dynamic pages, and a hosted alternative.

What you need before writing the script

Install the Selenium Python package and have a compatible browser and WebDriver available on the machine that runs the script. The API discussed here is documented in Selenium’s 4.49.0 Python reference. Create the output directory yourself rather than assuming it already exists; a missing directory is a common reason for a failed write.

python -m pip install selenium

The browser must be able to start in the same environment as your Python process. In a desktop session that means a normal installed browser; in a server or CI session you will generally configure the browser for that environment and make sure its driver is available.

Minimal Python code for a page screenshot

This is the complete current-window example. It navigates to the URL, saves a PNG, checks Selenium’s success flag, and shuts down the browser even if navigation or saving raises an exception.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Auto-Light Balance: RightLight boosts brightness by up to 50%, reducing shadows so you look your best—compared to previous-generation Logitech webcams (1)
  • Privacy with a Slide: The integrated webcam cover makes it easy to get total, reliable privacy when you're not on a video call
  • Built-In Mic: The built-in microphone lets others hear you clearly during video calls
  • Easy Plug-And-Play: The Brio 101 works with most video calling platforms, including Microsoft Teams, Zoom and Google Meet—no hassle; it just works
from pathlib import Path
from selenium import webdriver

output = Path('screenshots')
output.mkdir(parents=True, exist_ok=True)

driver = webdriver.Chrome()
try:
    driver.get('https://example.com')
    saved = driver.save_screenshot(str(output / 'page.png'))
    if not saved:
        raise OSError('Selenium could not save the screenshot')
finally:
    driver.quit()

save_screenshot() means “save a screenshot of the current window to a PNG image file.” Pass a filename ending in .png; using a full path makes the destination unambiguous. The method returns True after a successful write and False when Selenium encounters an I/O problem, so checking the value lets an automated job fail clearly instead of silently producing no file.

What “current window” means

The call captures the active WebDriver browsing context: the page currently displayed in the selected browser window or tab. It does not mean the operating-system desktop or the browser’s address bar and other chrome. If your script changes tabs, switch to the intended window handle before calling the method.

Wait for the page state you actually want

driver.get() waits for the navigation load event, but modern sites often render important content afterward with JavaScript. A screenshot taken immediately after the load event can therefore show a skeleton, an empty chart, or a missing image. Wait for a meaningful condition rather than adding an arbitrary long sleep.

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

output = Path('screenshots')
output.mkdir(parents=True, exist_ok=True)

driver = webdriver.Chrome()
try:
    driver.get('https://example.com/dashboard')
    WebDriverWait(driver, 20).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, 'main'))
    )
    if not driver.save_screenshot(str(output / 'dashboard.png')):
        raise OSError('Screenshot write failed')
finally:
    driver.quit()

Choose a selector that represents finished content on your page: a chart container, a heading, a table, or another element that appears only after the relevant request completes. If the page has several independent requests, wait for the last dependable visual marker. A fixed delay can still be useful for a known animation, but it makes fast runs unnecessarily slow and does not guarantee that a slow run is ready.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the capture scope

Decide whether you need the viewport, one component, or the entire document before selecting the method. Selenium documents these as distinct operations, and full-document support is not uniform across browser drivers.

Rank #2
Sale
EMEET C960 1080P Webcam with Microphone, 2 Mics, 90° FOV, Computer Camera
  • 1080P Webcam with Cover for Video Calls - EMEET computer webcam provides design and Optimization for professional video streaming. Realistic 1920 x 1080p video, 5-layer anti-glare lens, providing smooth video. C960 computer camera delivers 1920x1080 video with fixed focus (11.8–118.1 inches), so as to provide a clearer image. C960 USB webcam has a cover and can be removed automatically to meet your needs for privacy. For optimal image performance, use the webcam in a well-lit environment.
  • Built-in 2 Omnidirectional Mics - EMEET webcam with microphone for desktop features 2 built-in omnidirectional microphones, picking up your voice to create clear audio for communication. When installing the webcam, select EMEET C960 as the default microphone input device in your computer and video applications and select C960 as the default device in Zoom/Teams and ensure microphone permissions are enabled for proper use. Please note that C960 does not include built-in speakers.
  • Automatic Light Adjustment - Automatic exposure adjustment is applied in EMEET HD webcam 1080p so that the streaming webcam can deliver stable image performance. EMEET C960 camera for computer also features color adjustment and exposure optimization to help you look your best. For optimal video quality, it is recommended to use the webcam in normal or well-lit environments and select suitable video settings in your application. Proper lighting helps achieve a clearer and more balanced image.
  • Plug-and-Play & Upgraded USB Connectivity - New C960 webcam features both USB Type-A & A-to-C adapter connections for wider compatibility. For stable performance, connect the webcam directly to the computer's main USB port and ensure the device is recognized correctly. If a hub or docking station is used, please ensure it provides sufficient power and stable data transmission, as limited ports may affect performance. 90° wide-angle lens captures more participants without frequent adjustments.
  • High Compatibility & Multi Application - C960 webcam for laptop is compatible with Windows 10/11, macOS 10.14+, and Android TV 7.0+. Not supported: Windows Hello, TVs, tablets, or game consoles. It works with Zoom, Teams, Facetime, Google Meet, YouTube and more. Please select C960 webcam as the default camera and microphone device in your application and ensure camera/microphone permissions are enabled, especially on macOS. (Tips: Incompatible with Windows Hello)
Requirement Python call Scope and portability
Visible page view driver.save_screenshot('page.png') The general WebDriver current-window screenshot.
One element element.screenshot('card.png') Captures the located element instead of the whole window.
Entire long document driver.save_full_page_screenshot('page.png') Documented by the Python Firefox API; treat it as browser-specific, not a portable WebDriver guarantee.

Capture one element

Locate the component after it is present, then call the element’s screenshot method. Waiting for visibility is important because a node that exists in the DOM may still be hidden or not painted.

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

output = Path('screenshots')
output.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
    driver.get('https://example.com/products')
    card = WebDriverWait(driver, 15).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-testid="product-card"]'))
    )
    card.screenshot(str(output / 'product-card.png'))
finally:
    driver.quit()

An element screenshot is useful for a component catalog, a visual regression fixture, or a focused bug report. The file is still a PNG, and the element must be in the active browsing context.

Capture a full document with Firefox

The Firefox Python API documents save_full_page_screenshot(). Use a Firefox driver when you specifically need that API and verify the behavior against the browser version in your deployment; do not substitute it for the general method when the script must run unchanged on other drivers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from pathlib import Path
from selenium import webdriver

output = Path('screenshots')
output.mkdir(parents=True, exist_ok=True)
driver = webdriver.Firefox()
try:
    driver.get('https://example.com/article')
    if not driver.save_full_page_screenshot(str(output / 'article-full.png')):
        raise OSError('Full-page screenshot write failed')
finally:
    driver.quit()

If portability matters, use the ordinary current-window method and design the capture around the viewport, or implement a browser-specific branch explicitly. Do not label a viewport image “full page” merely because the page can be scrolled.

Return screenshot data instead of writing a file

The Python API also exposes the current-window image as data. get_screenshot_as_png() returns PNG bytes, while get_screenshot_as_base64() returns a Base64 string that can be embedded in HTML or sent to another service.

Rank #3
Sale
NexiGo N60 1080P Webcam with Microphone, Software Control & Privacy Cover, USB HD Computer Web Camera, Plug and Play, for Zoom/Skype/Teams, Conferencing and Video Calling
  • 【Full HD 1080P Webcam】Powered by a 1080p FHD two-MP CMOS, the NexiGo N60 Webcam produces exceptionally sharp and clear videos at resolutions up to 1920 x 1080 with 30fps. The 3.6mm glass lens provides a crisp image at fixed distances and is optimized between 19.6 inches to 13 feet, making it ideal for almost any indoor use.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 8, 10 & 11 / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.
  • 【Built-in Noise-Cancelling Microphone】The built-in noise-canceling microphone reduces ambient noise to enhance the sound quality of your video. Great for Zoom / Facetime / Video Calling / OBS / Twitch / Facebook / YouTube / Conferencing / Gaming / Streaming / Recording / Online School.
  • 【USB Webcam with Privacy Protection Cover】The privacy cover blocks the lens when the webcam is not in use. It's perfect to help provide security and peace of mind to anyone, from individuals to large companies. 【Note:】Please contact our support for firmware update if you have noticed any audio delays.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 10 & 11, Pro / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.
from selenium import webdriver

driver = webdriver.Chrome()
try:
    driver.get('https://example.com')
    png_bytes = driver.get_screenshot_as_png()
    with open('page.png', 'wb') as image_file:
        image_file.write(png_bytes)

    base64_image = driver.get_screenshot_as_base64()
    html_img = f'<img src="data:image/png;base64,{base64_image}" alt="Page">'
finally:
    driver.quit()

Use bytes when another Python function, an object store client, or an HTTP request accepts binary data. Use Base64 when the receiving format is text, such as an HTML data URI. These methods describe the same current browsing context as the file-saving method; they do not add full-page behavior.

Make screenshot jobs reliable

Use deterministic paths and names

Resolve the output directory before starting the browser, create it with parents=True, and use an explicit extension. For repeated runs, include a test name, URL slug, or run identifier in the filename so one capture does not overwrite another. In a temporary workspace, record the absolute path in the job log so an uploaded artifact can be found later.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Always release the browser

Put driver.quit() in finally. Selenium documents quit() as closing the browser and shutting down the driver executable. Without it, a failed navigation or assertion can leave browser processes running and eventually exhaust a worker.

Keep the capture context correct

Before saving, confirm that the script is on the expected URL, window handle, and frame. If you switched into an iframe to find an element, capture the element there or switch back to the intended context for a page screenshot. A screenshot can be perfectly valid while showing the wrong tab or an intermediate state.

Account for page-specific rendering

Wait for a visible application landmark, not just a generic document-ready event. If images are lazy-loaded only after scrolling, scroll to the relevant area before capturing and wait for the image or its loaded-state marker. For animations, wait until the final visual state or disable the animation in the test environment; otherwise two valid runs may differ.

Rank #4
Sale
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Crisp HD 720p/30 fps video calls with diagonal 55° field of view and auto light correction. Compatible with popular platforms including Skype and Zoom.
  • The built-in noise-reducing mic makes sure your voice comes across clearly up to 1.5 meters away, even if you’re in busy surroundings.
  • C270’s RightLight 2 feature adjusts to lighting conditions, producing brighter, contrasted images to help you look good in all your conference calls.
  • The adjustable universal clip lets you attach the camera securely to your screen or laptop, or fold the clip and set the webcam on a shelf. You’re always ready for your next video call.

Troubleshooting common failures

Symptom Likely cause Fix
No file appears The directory does not exist, the process lacks write permission, or the relative path points somewhere unexpected. Create the directory first, use an absolute path while diagnosing, check permissions, and test the Boolean return value.
save_screenshot() returns False Selenium could not complete the file write. Check the parent directory, filename extension, available disk space, and whether another process has locked the destination; raise an error instead of continuing.
The image is blank or shows a spinner The screenshot ran before asynchronous content finished. Add a condition wait for a page-specific visible element or loaded state. Do not rely only on the load event.
NoSuchElementException or an empty element image The selector is wrong, the element is inside an iframe, or it has not been rendered yet. Verify the selector in the target page, switch into the correct frame, and wait for presence or visibility before capturing.
Full-page method is missing or rejected The selected driver does not implement Firefox’s documented full-page Python method. Use Firefox for that API, or use the general current-window method and accept its viewport scope; keep browser-specific code behind an explicit branch.
Later tests become slow or fail to start a browser Earlier code did not call quit() after an exception. Wrap every session in try/finally, and clean up orphaned browser processes in the worker environment.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Other Selenium language bindings

The same capture idea exists in Selenium’s Java, Python, C#, Ruby, and JavaScript examples, but the return type and file operation differ by binding. Java obtains a screenshot through TakesScreenshot and OutputType.FILE before copying the file. Python and Ruby expose save_screenshot. JavaScript calls takeScreenshot() and returns Base64 data that your code writes to disk. Follow the binding’s documented output type rather than assuming that every method writes a file directly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Performance, storage, and operating cost

Launching a browser is usually more expensive than the screenshot call itself, so a batch job can reuse one driver for several navigations when isolation requirements allow it. Still wait for each page’s own readiness condition and clear any application state that would make one capture affect the next. If tests must be isolated, separate browser sessions are safer but consume more CPU and memory.

Viewport PNGs are generally smaller and faster to store than long-document captures. Full-page images can become large on pages with many high-resolution assets, so set retention and compression policies in the system that stores them. Selenium’s local call has no per-image hosted screenshot charge; your practical costs are the browser process, machine or CI resources, network traffic, and storage you choose. No universal file-size or timing figure applies because the page and environment determine both.

Or skip the browser setup

For a hosted capture, ScreenshotNeo is the first option to try: it produces clean shots, bills only clean shots, and its paid plans start at the lowest stated price. One GET request returns a PNG, JPEG, WebP, or PDF without you managing a browser session.

See the ScreenshotNeo API documentation for all parameters. Here are complete one-call examples using the same target URL:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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,
)
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}`);

ScreenshotNeo accepts the cookie or consent banner like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot. Each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers identify the page verdict and whether the request was billed.

The service also includes an MCP server for Claude, Cursor, and other MCP clients, with take_screenshot, get_page_info, and capture_pdf tools. Its 63 options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets plus custom viewports, retina scale, PDF paper and margin controls, custom CSS and JavaScript, pre-capture clicks, selector or network-idle waits, request and resource blocking, custom headers, cookies, user agents and Authorization, timezone and geolocation, transparent backgrounds, image resizing, selectable cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture for 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs are accepted to ease migration.

Plans

Plan Allowance and price
Free 1,000 shots per month, no card
Starter $5 for 3,000 shots
Growth $15 for 15,000 shots
Pro $39 for 60,000 shots
Scale $99 for 250,000 shots
Business $249 for 1,000,000 shots

Every feature is available on every plan, and yearly billing gives two months free. If you want to avoid browser installation, consent overlays, and manual cleanup, sign up for the free plan: it includes 1,000 screenshots a month with no card, while paid plans start at $5 for 3,000.

Frequently Asked Questions

Can Selenium save a JPEG or WebP directly with save_screenshot?

The Python save method writes a PNG file. If another format is required, obtain PNG bytes with get_screenshot_as_png() and convert them with an image-processing library in your application, or use a service that returns JPEG or WebP.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I capture a tab opened by target=”_blank”?

Read the driver’s window handles, switch to the handle for the newly opened tab with driver.switch_to.window(…), wait for its content, and then call the screenshot method. Selenium captures whichever browsing context is active at the moment of the call.

Can I use these files in a visual-regression pipeline?

Yes. Give each case a deterministic filename, wait for a stable visual marker, check the save result, and publish the PNG directory as the pipeline’s artifact. Keep browser and viewport settings consistent between runs so differences represent page changes rather than setup changes.

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.