October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Take Website Screenshots for Visual Testing with Selenium

Learn how to capture page or element screenshots with Selenium for visual testing, wait for dynamic content, and keep comparisons repeatable.

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.

Use Selenium WebDriver to capture either the current browsing context or a specific element, then save the image as a test artifact. For reliable visual checks, wait for the page’s actual visual state—not just navigation to finish—and keep the browser environment consistent. Selenium captures screenshots; a separate review or image-comparison process determines whether a difference is acceptable.

Capture a screenshot with Selenium

The basic workflow is: open a WebDriver session, navigate to the page, wait for the state you want to test, and save a page or element screenshot. Selenium’s official examples show screenshot capture in several language bindings; the exact save method depends on the binding. Selenium’s screenshot examples

Python example: page and element screenshots

This runnable example assumes Selenium is installed, the browser and driver are available to the environment, and the page contains a visible main element. Create the artifacts directory before running it, or change the output paths to an existing directory.

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_dir = Path("artifacts")
output_dir.mkdir(parents=True, exist_ok=True)

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")

    WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
    )

    driver.save_screenshot(str(output_dir / "example-page.png"))

    main = driver.find_element(By.CSS_SELECTOR, "main")
    main.screenshot(str(output_dir / "example-main.png"))
finally:
    driver.quit()

The ten-second wait and selector are illustrative, not Selenium defaults. Replace the URL and selector with your test page and a condition that represents the state you intend to compare. The page capture and element capture use Selenium’s documented Python methods. Selenium screenshot examples

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

Wait for visual readiness before capture

A successful navigation does not guarantee that the page has finished rendering the content relevant to your test. A single-page application may fetch or display content after document.readyState becomes complete. Selenium explicitly cautions that ready state “does not necessarily mean that the page has finished loading.” Selenium Browser Options

Wait for an application-specific visual precondition, such as the target element becoming visible or a loading indicator disappearing. The right condition depends on the page; there is no universal Selenium wait that proves every image, animation, font, or asynchronous component is visually settled.

Page-load strategies affect navigation, not application readiness

  • normal: the default strategy; navigation waits for the page load event.
  • eager: navigation returns after DOMContentLoaded; other resources may still be loading.
  • none: navigation does not block on page loading.

Choosing eager or none can change when a navigation command returns, but it does not make dynamic page content ready. Use an explicit wait for the visual condition your test needs whichever strategy you choose. Selenium Browser Options

Choose the screenshot scope

Capture the page or current browsing context

Use the WebDriver screenshot method when the assertion concerns the page or current browsing context as a whole. This is useful for checking layout, spacing, and interactions across multiple regions. The precise capture scope can depend on the browser and driver.

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

Capture one element

Use an element screenshot when the test is focused on a component, such as a navigation bar or product card. A focused image is easier to inspect when changes elsewhere on the page are irrelevant. Selenium documents element screenshot methods alongside current-context examples. Selenium screenshot examples

The JavaScript WebDriver API describes its screenshot scope as best effort: entire page, current window, visible portion of the current frame, then the display containing the browser. Treat that as the API’s stated order of attempts, not a guarantee that every browser and driver returns identical dimensions. Selenium JavaScript WebDriver API

Make captures useful for visual checks

Use deterministic artifact names

Name screenshots by page and application state, such as checkout-empty-cart-chrome.png. Include browser or viewport details when they distinguish one run from another. Consistent names make it easier to locate a failed test’s artifact and compare it with the intended baseline.

Keep the rendering environment aligned

For pixel-oriented comparisons, record and control the browser, driver, viewport, operating system or container, and other relevant rendering inputs. Browser options and capabilities vary by browser. For Chrome, Selenium notes that the Chrome and ChromeDriver major versions must match. Selenium Chrome-specific functionality and Selenium supported browsers

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.

The Selenium documentation cited here does not prescribe a canonical viewport, font policy, device scale factor, pixel tolerance, masking rule, or visual-diff report format. Choose and document those separately for the project; otherwise, environment or rendering differences can be mistaken for application changes.

Separate capture from comparison

A screenshot is an image artifact, not a regression verdict. Selenium’s screenshot and browser-options documentation explains how to capture and configure a session; it does not define an image-diff algorithm or decide which visual changes should fail a test. Your workflow can store the artifact for manual review or pass it to a separately selected comparison process with project-specific rules.

Or skip the browser setup

If you need a screenshot from an API rather than an in-test WebDriver session, ScreenshotNeo returns an image or PDF from one GET request. It is not a replacement for Selenium’s browser session when your test must exercise an authenticated, interactive application state; it is an option for capturing a URL without setting up browser automation yourself.

For example, save a PNG response with cURL. See the ScreenshotNeo API documentation for the request options and response details.

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://example.com -o shot.png
  • Cookie and consent banners are accepted, and 60+ known consent platforms, newsletter popups, and chat widgets are removed before capture; each of these steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Responses include X-Page-Verdict and X-Billed headers.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.
  • The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.

Sign up for 1,000 free screenshots a month with no card.

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

Troubleshoot common capture problems

The screenshot is blank or missing expected content

  • Likely cause: capture ran before the relevant component rendered, even though navigation returned.
  • Fix: wait for a visible target element or for the page’s loading indicator to disappear. Confirm the wait condition matches the state being tested.

The screenshot file is not created

  • Likely cause: the output directory does not exist, the process cannot write there, or the test ends before the capture call completes.
  • Fix: create the directory, use a writable path, and check that the screenshot method returned successfully before the session is closed.

Chrome fails to start or the session cannot be created

  • Likely cause: Chrome and ChromeDriver major versions do not match, or the browser/driver is unavailable in the environment.
  • Fix: install compatible versions and verify the browser-specific setup for the environment. Selenium’s Chrome guidance calls out the major-version match requirement. Selenium Chrome-specific functionality

Visual comparisons change between runs

  • Likely cause: browser, driver, viewport, operating system, dynamic content, or timing differs between captures.
  • Fix: stabilize the test state, use a consistent browser configuration, and record the environment with the baseline. Define project-specific handling for variable content and acceptable differences; Selenium does not provide a universal pixel threshold.

Element capture fails or clips content

  • Likely cause: the element is not yet present or visible, or the particular browser/driver handles capture scope differently.
  • Fix: wait for the target element, confirm the selector identifies the intended node, and use a page-level capture if the test needs surrounding context. Screenshot scope can vary by implementation.

Frequently Asked Questions

Does Selenium compare a screenshot against a baseline?

No. Selenium captures the image; a separate comparison or review process must decide whether a difference is acceptable.

Can I capture only one component instead of the whole page?

Yes. Selenium supports element screenshots; use one when the test concerns a specific component rather than the full layout.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.