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

To capture what Selenium’s browser window currently renders, navigate with WebDriver and call its driver-level screenshot method. In Python, driver.save_screenshot("screenshot.png") writes a PNG of the current window. That is a viewport/current-window capture, not automatically a stitched image of the entire document or a screenshot of one element.

The sections below show a reliable Python workflow, controlled dimensions, explicit waits, in-memory output, element and full-page alternatives, Java, troubleshooting, and a hosted option when you do not want to operate a browser.

What a Selenium viewport screenshot contains

Selenium’s ordinary driver screenshot targets the current browser window. It captures the rendered browsing context at the moment the command runs. A long page is therefore limited to the visible window rather than every vertical section that would require scrolling.

Requirement Selenium approach Result
Visible viewport/current window Driver screenshot method PNG of the current window
One component Call the screenshot method on a WebElement Image of that element
Entire document Firefox full-page methods such as save_full_page_screenshot Browser-specific full-document capture

Choose the scope before writing your test. Asking for a full-page image when you need the visible viewport can make visual comparisons misleading; asking for a viewport image when you need every section of a page will omit content below the fold.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 4x optical zoom with a 27mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen with 2 AA alkaline batteries for convenient on-the-go use

Prerequisites and a minimal Python capture

Install and prepare the browser

Install Selenium in the Python environment that runs the test and make a supported browser available. The browser and its WebDriver must be discoverable by Selenium in that environment. In CI, use the same browser mode and dimensions on every run.

Save a viewport PNG

This complete example opens a page, saves the current-window image, reports whether the file operation succeeded, and always closes the session.

from selenium import webdriver


driver = webdriver.Chrome()
try:
    driver.get("https://www.example.com")
    ok = driver.save_screenshot("screenshot.png")
    if not ok:
        raise RuntimeError("Selenium could not save screenshot.png")
finally:
    driver.quit()

The filename should use a .png extension. Selenium’s file-saving methods return a Boolean success value, so checking it catches a failed write instead of silently continuing with a missing artifact.

Make the viewport reproducible

Set the window before navigation or capture

Responsive layouts can change when the browser window changes. Set a known size and record the browser, browser version, headed or headless mode, and dimensions with the test result.

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


driver = webdriver.Chrome()
try:
    driver.set_window_size(1280, 900)
    driver.get("https://www.example.com")
    if not driver.save_screenshot("viewport-1280x900.png"):
        raise RuntimeError("Screenshot write failed")
finally:
    driver.quit()

set_window_size controls the browser window; it does not establish a universal one-to-one conversion to CSS viewport pixels. Operating-system decorations, browser chrome, and browser implementation can affect the relationship. If exact CSS dimensions matter, verify the rendered dimensions in the page and keep the environment consistent rather than assuming that the outer size is the viewport size.

Rank #2
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 5x optical zoom with a 28mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen and a rechargeable lithium-ion battery for on-the-go use

Wait for the state you intend to test

The screenshot command does not know that your application’s asynchronous chart, image, or dialog is ready. Wait for a test-specific condition before capturing.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait


driver = webdriver.Chrome()
try:
    driver.set_window_size(1280, 900)
    driver.get("https://www.example.com/dashboard")
    WebDriverWait(driver, 20).until(
        lambda d: d.find_element(By.CSS_SELECTOR, "[data-testid='chart']").is_displayed()
    )
    if not driver.save_screenshot("dashboard.png"):
        raise RuntimeError("Screenshot write failed")
finally:
    driver.quit()

Use the condition that represents visual readiness: an element becoming visible, a loading marker disappearing, or a page-specific state becoming true. A fixed sleep can be useful for a known animation, but an explicit condition usually avoids both premature captures and unnecessary delay.

Choose the output form you need

Write directly to a file

save_screenshot(filename) is the short path for a PNG file. Python also exposes get_screenshot_as_file(filename), which serves the same file-oriented use case and reports success as a Boolean.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ok = driver.get_screenshot_as_file("artifacts/home.png")
if not ok:
    raise IOError("Unable to write artifacts/home.png")

Create the destination directory before calling the method and use unique names when parallel tests could otherwise overwrite one another.

Keep PNG bytes in memory

Use get_screenshot_as_png() when the next step uploads, hashes, analyzes, or attaches the image without an intermediate file.

Rank #3
Teslong Articulating Borescope for Mechanic Automotive HVAC Wall Inspection
  • Easily Maneuver Your View: Tired of struggling with hard-to-reach areas during inspections? This two-way articulating borescope effortlessly navigates tight and complex spaces with its flexible and maneuverable probe. Enjoy crystal-clear visual feedback that saves you both time and money. Whether for automotive maintenance or household inspections, this tool transforms your inspection journey, making the process faster and easier than ever.
  • See Every Detail in Vivid Clarity: Experience the exceptional image quality of our 4.5-inch IPS LCD color screen, delivering sharp, high-resolution visuals. Whether you’re in bright sunlight or dim conditions, this display ensures you won’t miss a thing. Plus, with no app required, it's ready to go whenever you are!
  • Master the Most Challenging Inspections: Equipped with a 5FT semi-rigid gooseneck cable, this borescope provides the ideal combination of flexibility and stability, allowing you to navigate tight, intricate spaces with ease. The cable retains its shape as you guide it, giving you precise control for thorough inspections. Designed for versatility, it adapts effortlessly to various environments, ensuring no detail goes unnoticed.
  • Light Up the Darkest Corners: Equipped with built-in high-brightness LED lights on the camera probe, you’ll have the visibility you need even in the darkest environments. The adjustable illumination allows you to customize the brightness for every inspection, ensuring that no detail goes unnoticed in tight or confined spaces.
  • Ergonomics Meet Efficiency: This borescope is thoughtfully designed for maximum comfort and usability. The centrally located articulating joystick allows for effortless one-handed operation with either hand. The photo button is conveniently positioned on the back, making it easy to capture images or videos during inspections. Lightweight and compact, this borescope ensures prolonged use without fatigue, perfect for on-the-go inspections.
png_bytes = driver.get_screenshot_as_png()
with open("screenshot-copy.png", "wb") as image_file:
    image_file.write(png_bytes)

Return Base64

get_screenshot_as_base64() is useful when a reporting system or JSON payload expects a Base64 string.

encoded = driver.get_screenshot_as_base64()
print(encoded[:40] + "...")

Base64 is text representing the same PNG; it is not a different capture scope. Choose it only when the receiving interface requires text.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Capture one element instead of the viewport

When the artifact should contain only a component—such as a header, invoice, or chart—locate the element and invoke its screenshot method. This avoids manually calculating coordinates and makes the intended scope explicit.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait


driver = webdriver.Chrome()
try:
    driver.get("https://www.example.com")
    header = WebDriverWait(driver, 20).until(
        lambda d: d.find_element(By.CSS_SELECTOR, "header")
    )
    if not header.screenshot("header.png"):
        raise RuntimeError("Element screenshot write failed")
finally:
    driver.quit()

Use the driver method when the viewport is the subject of the visual test; use the element method when surrounding page content would be noise.

Capture a full document when that is the requirement

A viewport capture is intentionally not a full-page capture. Selenium documents full-page screenshot methods separately for Firefox in Python, including get_full_page_screenshot_as_file and save_full_page_screenshot.

Rank #4
4K Digital Camera for Photography, 50MP Vlogging Camera for YouTube, Compact Cameras with 2.8" 180° Flip Screen, 16X Digital Zoom, Point and Shoot Camera with 32GB SD for Beginners, Travel, Family
  • 【4K UHD & 50MP High-Def Shooting with 180° Flip Screen】Capture stunning videos and stills in ultra HD with this digital camera’s 2.8″ flip screen for framing. Whether documenting family trips, everyday moments, or creating video content, it delivers clear images and smooth video.Ideal mini camera & vlog camera companion.
  • 【16X Digital Zoom & Precise Autofocus】Get closer with 16X digital zoom and sharp autofocus on this point and shoot digital cameras camcorder. Even if you shoot from a distance, you can still take clear and beautiful photos. Whether shooting landscapes or portraits, this cameras for photography delivers crisp clarity every time.
  • 【Portable & Multi-Functional Design】Our mini camera weighs just 0.6 lbs and serves as a video camera, camcorder, and action camera. Built-in flash, time-lapse, and slow-motion modes make it the ultimate kids camera on the go.Record the beautiful and happy life of children.
  • 【Versatile for YouTube & Beyond】This vlog camera doubles as a webcam and supports Data line transfer for seamless sharing. Connect to PC for live streaming and video chats on youtube, making it the perfect digital camera for content creators.Whether you're recording a vlog on the go, filming a makeup tutorial, or capturing fun moments with friends, this camera has you covered.
  • 【Complete Accessories & Service】The camera comes with a 1500mAh rechargeable battery, which can be used continuously for 4-5 hours. Accessories includes a lens cleaning cloth, Type-C cable, 32GB card, carrying case, and lanyard.. Enjoy an 18-month WARRANTY and responsive customer support. Your camara awaits—ready for every adventure!
from selenium import webdriver


driver = webdriver.Firefox()
try:
    driver.get("https://www.example.com/long-page")
    if not driver.save_full_page_screenshot("full-document.png"):
        raise RuntimeError("Full-page screenshot write failed")
finally:
    driver.quit()

Because these methods are browser-specific, confirm that the browser in your test environment supports the full-page API you select. Do not substitute it for the generic current-window method when cross-browser viewport behavior is what you are validating.

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

Java WebDriver example

In Java, cast the driver to Selenium’s TakesScreenshot interface and request a file output. The interface also supports other output targets.

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class ViewportShot {
    public static void main(String[] args) throws IOException {
        WebDriver driver = new ChromeDriver();
        try {
            driver.get("https://www.example.com");
            File temporary = ((TakesScreenshot) driver)
                    .getScreenshotAs(OutputType.FILE);
            Files.copy(temporary.toPath(), new File("screenshot.png").toPath());
        } finally {
            driver.quit();
        }
    }
}

The Java driver-level call has the same scope decision as Python: it captures the current window, while an element-level call targets that element.

Troubleshoot common failures

Symptom Likely cause Fix
File is missing and the test continues The Boolean result was ignored, or the destination directory does not exist. Create the directory, use an absolute or verified path, and fail the test when the method returns False.
The image shows a spinner or an empty panel Capture ran before application content finished rendering. Wait for a page-specific element or state with WebDriverWait; do not assume navigation alone means visual readiness.
Layout differs between local and CI Window dimensions, browser version, operating system, or headed/headless mode differ. Set the window size explicitly and record those environment details for each artifact.
Only the top portion of a long page appears The driver method is a viewport capture by design. Use an element screenshot for a component or Firefox’s documented full-page method when the whole document is required.
Element capture raises a lookup or visibility error The selector is wrong, the element has not appeared, or it is not displayed. Wait for the selector and the visual condition, then capture the returned WebElement.
Parallel tests overwrite images Every test uses the same filename. Include a test identifier, timestamp, or worker identifier in the path and write to separate artifact directories.

Performance, reliability, and storage considerations

  • Capture only when it adds evidence. A screenshot after every step increases disk usage and report size. Keep viewport captures at assertion points and retain failure artifacts separately.
  • Prefer explicit readiness signals. They reduce flaky images caused by racing network or rendering work.
  • Keep dimensions stable. Responsive breakpoints can change both layout and element visibility, so a dimension change is a test-input change, not merely a cosmetic difference.
  • Clean up in a finally block. Quitting the driver releases the browser even when navigation or file writing fails.
  • Choose the smallest transport. Use a file for ordinary test artifacts, bytes for programmatic processing, and Base64 only for interfaces that require text.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a URL image rather than a browser session you operate yourself, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF. 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. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers.

See the full parameter list and request behavior in the ScreenshotNeo documentation. A basic cURL request is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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,
)
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 fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo also supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets and custom viewports, retina scale, PDF paper settings and page ranges, custom CSS and JavaScript, clicks before capture, selector waits or network-idle waits, hidden selectors, request and resource blocking, custom headers/cookies/user agents, Authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

Best Value
Sale
Fazoxo 2K Security Camera Wireless Outdoor, WiFi Cameras for Home Security
  • Solar-Powered for Extended Battery Life: The wirless camera comes with a high-efficiency solar panel(wire length 59 inch), designed to provide a consistent supplemental power source under adequate sunlight. This significantly reduces the need for manual recharging and supports a more sustainable, low-maintenance surveillance experience. It's an ideal power solution for long-term,wire-free outdoor installation
  • 2K UHD Clarity with Night Vision & 3x Zoom: This camera delivers crisp, detailed video day and night. It features standard infrared night vision for clear black-and-white footage in the dark, and a built-in spotlight mode that activates full-color night vision for more vivid details. The 3x digital zoom lets you focus on key areas like faces or license plates. (Compatible with 2.4GHz Wi-Fi networks only)
  • Flexible Storage Options: Your event-triggered videos are securely backed up with cloud storage(3 day trial). For extended coverage, you can upgrade to premium cloud plans (subscription required) or insert a microSD card (up to 128GB, not included) for local recording of motion events
  • Smart AI Detection & Instant Alerts: Receive prompt phone notifications when motion is detected. The basic motion detection works without any subscription. Can be individually set to recognize humans, so that all moving objects except for humans will not trigger detection
  • Two-Way Audio & Real-Time Interaction: Built-in microphone and speaker let you communicate directly through the app. Greet visitors, deter unwanted guests, or check in on your family and pets from anywhere

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; Growth is $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000. Yearly billing gives two months free, and every feature is available on every plan. Create a free ScreenshotNeo account to try it without a card.

Frequently Asked Questions

Does Selenium wait for fonts and animations before taking the image?

No. The command captures the rendered state at that instant. If a font swap or animation matters, add a readiness condition—or wait for the specific animation state—in your test before calling the screenshot method.

Can I use a non-PNG extension with Selenium’s file method?

Use a filename ending in .png for Selenium’s documented file-saving screenshot methods. If another format is required, convert the PNG after capture or use a service that returns the required format directly.

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

Should visual-test artifacts be checked into source control?

Usually no. Store them in your test-report or CI-artifact system, apply retention rules, and keep only deliberately approved baselines in version control.

Quick Recap

SaleBestseller No. 1
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$99.99
Bestseller No. 2
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$139.99

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.