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.

Selenium WebDriver can capture a screenshot of a browser page during a test and save it as an image. In Python, the documented methods include save_screenshot() and get_screenshot_as_file() for PNG files, as well as methods that return image bytes or Base64 data. The exact screenshot scope depends on the binding and browser driver: a driver screenshot, an element screenshot, and a full-document screenshot are not interchangeable capabilities. A screenshot helps investigate what a test saw; visual regression testing additionally needs a baseline, a comparison method, and review of the differences.

What Selenium screenshot testing does

Selenium’s browser-driver API lets a test capture an image of browser content at a chosen point in the test. The image can help a developer inspect a failure, preserve evidence for a report, or serve as input to a separate visual comparison process. The capture call produces an image; it does not decide whether the page looks correct.

There are two related but distinct uses:

  • Failure diagnosis: keep an image of the browser when an assertion or other test step fails, so a person can inspect the visible state.
  • Visual regression testing: compare a new capture against a known baseline, identify visual differences, and decide whether those differences are acceptable.

Do not assume that every Selenium binding or browser driver captures the same region or supports the same screenshot options. The Java TakesScreenshot API describes capture from a driver or HTML element. Selenium’s Python Firefox API also includes a full-document screenshot method, while the Python API documentation describes current-window PNG capture and image data forms. Check the documentation for the binding, browser, and driver actually used by your tests.

Save a Selenium screenshot in Python

This example uses Selenium’s Python API to capture the current browser window after the page has reached a test-relevant state. It saves a PNG file in the process’s current working directory. Replace the example URL and locator with the page and condition your test needs.

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.
#1 Best Overall
DGK Color Tools High Resolution 8.5x11 Chrome SD Lens Test Chart, 3-P
  • SUPERIOR IMAGE QUALITY - Achieve optimal lens performance with these high-resolution charts, ensuring your photos and videos are sharp, clear, and professional-grade every time.
  • ENHANCED EASE OF USE - Simplify your lens testing and calibration process with these user-friendly 8.5x11" charts, designed for quick and accurate assessments of lens performance.
  • GUARANTEED DURABILITY - Benefit from the robust construction of these chrome SD test charts, built to withstand frequent use and maintain their accuracy over extended periods.
  • EXCELLENT PRICE VALUE - Get three high-quality lens test charts for comprehensive testing and calibration, offering exceptional value for professionals and enthusiasts alike.
  • WIDE COMPATIBILITY - These versatile charts are ideal for lens testing, calibration, resolution, and color calibration across various digital photo and video equipment setups.
from pathlib import Path
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

output = Path("artifacts")
output.mkdir(parents=True, exist_ok=True)

# Choose the driver and browser configuration appropriate to your environment.
driver = webdriver.Chrome()
try:
    driver.get("https://example.com")

    # Wait for a meaningful page condition rather than capturing immediately.
    WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.TAG_NAME, "h1"))
    )

    saved = driver.save_screenshot(str(output / "page.png"))
    if not saved:
        raise RuntimeError("WebDriver did not save the screenshot")
finally:
    driver.quit()

The wait in the example is a test condition, not a guarantee that every image, animation, or asynchronous widget on the page has finished. Pick a condition that corresponds to the state the test is intended to inspect. A page title, a visible element, or an application-specific ready indicator may be more useful than an arbitrary delay. For visual comparisons, also control content that changes between runs.

Choose a Python output form

  • save_screenshot(path) saves the current-window screenshot as a PNG file and returns a success value. Check that value when the artifact is important.
  • get_screenshot_as_file(path) is another documented Python method for saving PNG output to a file.
  • get_screenshot_as_png() returns PNG bytes. This is useful when the test runner or artifact system accepts an in-memory image and you do not want to manage a temporary file.
  • get_screenshot_as_base64() returns Base64-encoded screenshot data, which can be embedded or transferred by a reporting system that expects that representation.

These methods describe output representation, not a promise that every driver will capture a full page. If your test needs an element or an entire document rather than the browser’s current window, confirm that the chosen browser and binding support the relevant scope.

Choose the screenshot scope deliberately

A screenshot is only useful if its captured area matches the question being investigated. Before relying on an artifact, establish what the active API means by “screenshot” in your environment.

Rank #2
ARTIBETTER Camera Focus Calibration Card Lens Test Chart Color Wheel Chart for CCTV Installation Alignment Indoor Outdoor Use 15.7 X 12.6 Inch
  • : includes , helping technicians quickly master calibration techniques and network performance, focus test chart, focus adjustment card
  • Sturdy build: constructed for durability, decreasing the frequency of replacements and suitable for longterm projects, circle of color mixing,focus testing tool for cctv
  • Construction: suit for longevity, reducing replacement needs and suit for longterm projects,classroom color wheel chart,color test cards
  • Clear images: makes sharp and clear imaging for cameras, enhancing the of security footage,cctv installation test tool,security camera assembly parts
  • Lens calibration: makes the lens adjustment process, enabling deployment of equipment,color test chart,lens chart
Scope Useful for What to verify
Driver or current-window capture Inspecting the visible browser state around a test failure or comparing a consistent viewport. Whether the driver captures the viewport or uses different behavior; set and keep the viewport consistent for comparisons.
Element capture Focusing on a component, widget, or region without treating the rest of the page as part of the result. Whether the language binding and driver expose element capture, and how the element is positioned or clipped.
Full-document capture Reviewing content that extends beyond the visible window. Whether the specific browser API supports it. Selenium’s Python Firefox API documents a full-document method; do not generalize that to every driver.

For Java, the TakesScreenshot interface documents capture through a driver or HTML element and examples that return a file or Base64 data. For Python, use the methods documented for your target WebDriver. A method available in one browser-specific API is not evidence that the same method or scope works identically in another browser.

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

Capture screenshots when tests fail

Failure-only screenshots preserve evidence at the point when it is most valuable while avoiding an image for every passing test. The simplest implementation is to catch a test failure at the framework boundary, capture from the still-open driver, attach or move the image into the test report, and then allow the test to remain failed. The precise hook syntax depends on the test framework; the important lifecycle requirement is that capture happens before the browser session is closed.

  1. Keep the WebDriver accessible to the test teardown or failure hook.
  2. Determine whether the test failed before quitting the driver.
  3. Save the capture to a predictable artifact location, using a filename that identifies the test without overwriting other failures.
  4. Attach or publish the file through the test runner’s reporting mechanism.
  5. Close the browser even if screenshot saving or report attachment fails.

Selenide documents automatic screenshots on test failure and configuration for the reports folder. Its integrations also describe capture on successful tests, which is an optional configuration choice rather than a requirement for Selenium screenshot capture. If using a framework integration, check its own configuration and artifact lifecycle rather than assuming it behaves like a direct WebDriver call.

Rank #3
Sale
Artibetter Lens Test Chart Color Calibration Card Lens Focus Adjustment Chart Color Wheel CCTV Camera Calibration Tool Testing Card for Monitoring Systems
  • Paper imaging: makes cameras deliver crisp and clear images, enhancing the of monitoring systems.
  • Easy calibration: simplifie the lens adjustment process, improving facilitating quick deployment of devices.
  • Adaptable use: offers precise image evaluation for both indoor and outdoor environments, meeting various needs.
  • Sturdy build: constructed for durability, decreasing the frequency of replacements and suitable for longterm projects.
  • patterns: features intuitive , allowing technicians to quickly learn calibration techniques and optimize network performance.

A robust failure hook should not turn a useful test failure into an unrelated teardown failure. Treat screenshot capture as best-effort: record an error if the driver is already unavailable or the save fails, but preserve the original assertion or test exception. In parallel tests, give each test its own artifact name or directory so captures do not overwrite one another.

Turn screenshots into visual regression tests

A screenshot alone is not a visual regression test. A basic comparison workflow has three parts: a baseline image representing an accepted state, a repeatable capture, and a method for comparing the new image with the baseline. A person or an explicit acceptance policy must then review whether any differences are meaningful.

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

Make capture conditions repeatable

  • Browser and operating system: run baseline generation and comparison in the same environment. Playwright’s official visual-comparison guidance notes that rendering can differ with host OS, browser version, settings, hardware, power source, and headless mode. That is comparative guidance about rendering consistency, not a Selenium-specific guarantee.
  • Viewport and scale: use the same window dimensions and device scale assumptions for each run. A different viewport can reflow content and change the image for legitimate reasons.
  • Page state: wait for the same meaningful application state before capture. Avoid comparing a loading state in one run with a settled page in another.
  • Dynamic content: decide how to handle timestamps, rotating promotions, personalized content, randomized values, animations, and other changing regions. Stabilize, mask, or exclude such content only when that matches the purpose of the test.
  • Baseline changes: treat baseline updates as reviewed test changes. Regenerating a baseline automatically after every mismatch can conceal a real regression.

Review differences, not just pass or fail

A comparison tool can report differing pixels or create a diff image, but a difference is not automatically a defect. Font rendering, antialiasing, small layout shifts, and intentionally changing content can create differences that require judgment. Decide how the team reviews diffs, who can approve baseline changes, and where the source capture and comparison output are retained.

Rank #4
AMQYDT Camera Resolution Test Chart, Resolution Test Chart with ±5μm Accuracy 0.25mm Optical Grade Photographic Paper, Anti-Glare Matte Surface for Camera Calibration Lens Testing 378mm*213mm
  • 【Professional Calibration Tool】: Designed for camera calibration and image quality evaluation, this resolution test chart helps assess resolution, sharpness, distortion, and overall imaging performance.
  • 【Ultra-Precision Pattern】: Manufactured with ±5μm accuracy, the chart features clearly defined corner points and test patterns for repeatable and reliable camera and lens testing.
  • 【Anti-Glare Matte Surface】: Made with optical-grade photographic paper and a diffuse reflection surface, reducing glare while providing consistent light distribution during testing.
  • 【Durable Optical Material】: Built with 0.25mm thick optical paper and precision spray coating to maintain pattern clarity and resist fading for studio and field applications.
  • 【All-In-One Testing Chart】: Integrates resolution targets, color patches, and distortion grids for comprehensive evaluation of focus accuracy, color performance, and geometric imaging characteristics.

Keep the dimensions of the comparison explicit: same target URL or application state, same capture scope, same viewport, same relevant browser environment, and same handling of dynamic regions. If the environment changes, regenerate or validate baselines deliberately instead of treating the new images as directly equivalent to the old ones.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

Symptom Likely cause What to do
The image shows a loading screen or incomplete content. The capture happened before the test reached its intended state. Wait for a specific visible element or application-ready condition before calling the screenshot method.
The screenshot is smaller than the full page. The selected API captures the current window rather than the full document. Confirm the documented scope for that browser and binding; use a documented full-document method only where supported.
A screenshot call fails during teardown. The browser session has already been closed, or the driver is no longer usable. Capture in a failure hook before quitting the driver; preserve the original test error if capture also fails.
One test’s artifact replaces another’s. Parallel tests wrote to the same path. Use a per-test filename or directory and ensure the report system retains distinct artifacts.
Images differ across machines despite unchanged application code. Rendering environments or capture conditions differ. Align the browser, OS, settings, viewport, and execution mode used for baseline generation and comparison; inspect the diff before accepting it.
The artifact exists but cannot be found in the report. The file was saved locally but not attached or published by the test runner. Check the configured artifact directory and the framework’s report-attachment step.

Performance, reliability, and artifact handling

Captures add work and produce files, so choose their frequency according to the debugging value. Failure-only capture is often a practical default for functional tests; capture passing tests when a specific report or visual baseline workflow needs those artifacts. Large or full-document images can increase storage and transfer costs for a test system, so retain only the artifacts your team uses and apply the test runner’s retention policy.

Remote WebDriver and grid sessions introduce an additional handoff: the screenshot must be returned by the remote driver and then saved or attached by the test process. The APIs cited here do not establish identical behavior for every remote-grid provider, so verify the setup used by your team. For reliable triage, include enough context in the artifact name or report to identify the test, run, browser, and environment without exposing credentials or sensitive page content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
NUOBESTY Camera Focus Test Chart Camera Lens Monitoring Focus Test Card
  • Focus Check: This camera focus test chart gives you a clear reference for checking sharpness and alignment, helping you fine-tune image clarity during setup without guesswork
  • Color Reference: the color wheel chart layout supports image comparison, making it easier to review color response and adjust camera settings with a more consistent visual target
  • Easy Setup: Use this lens test chart as a simple installation test tool for routine camera setup, maintenance, or checks at home or in everyday monitoring projects
  • Clear Viewing: the large-format paper card offers an easy-to-see , so you can inspect focus and alignment more comfortably while keeping light and easy to handle
  • Whats Included: Each package includes 1 color test chart, giving you a practical camera lens test chart for repeat use, simple storage, and a ready-to-gift option for a camera setup kit

Screenshots can contain account details, personal data, or internal application information. Treat them as test artifacts with access and retention controls, and avoid capturing secrets unnecessarily. Before publishing or sharing a report externally, inspect what the page contains.

Or skip the browser setup

If the goal is a website screenshot rather than exercising Selenium interactions, ScreenshotNeo can capture a URL with one GET request. It is a screenshot API and MCP server from Yorker Media. Its clean-shot steps accept cookie or consent banners like a visitor and remove 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Responses identify page verdict and billing status, and bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf.

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://example.com 
  -o shot.webp

See the ScreenshotNeo API documentation for request options. Free includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo and get 1,000 screenshots a month free, with no card.

Frequently Asked Questions

Does a Selenium screenshot call verify that a page looks correct?

No. It captures an image. A visual test needs a baseline, a comparison process, and a decision about the differences.

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

Can Selenium save screenshots as something other than PNG?

The Python screenshot methods described here provide PNG files, PNG bytes, or Base64-encoded screenshot data. This article does not establish another image format for those methods.

Can I use a Selenium screenshot for a PDF report?

A screenshot is an image capture, not a PDF-generation workflow. Use a separate PDF-capable method if the deliverable must be a PDF.

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.