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

To take multiple screenshots in a Selenium WebDriver test, call Selenium’s TakesScreenshot.getScreenshotAs() method each time you reach a state you want to record, then save each capture to a different path. There is no special multi-screenshot call: repeated captures with unique filenames preserve each checkpoint.

Capture and save multiple screenshots in Java

Selenium’s TakesScreenshot interface provides getScreenshotAs(OutputType). The API describes it as an interface for a driver or HTML element that can capture a screenshot and store it in different ways. For a normal page capture, use the driver; for a cropped image of one element, use the element instead.

The helper below takes a driver and destination path, captures the current state as a temporary file, and copies it to the requested destination. It creates the parent directory if necessary and replaces an existing file at that exact path. Use unique destinations for checkpoints you need to keep.

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public final class Screenshots {
    private Screenshots() {
    }

    public static void save(WebDriver driver, Path destination) throws IOException {
        Path parent = destination.getParent();
        if (parent != null) {
            Files.createDirectories(parent);
        }

        File temporaryScreenshot = ((TakesScreenshot) driver)
                .getScreenshotAs(OutputType.FILE);
        Files.copy(temporaryScreenshot.toPath(), destination,
                StandardCopyOption.REPLACE_EXISTING);
    }
}

Call the helper after the page reaches each meaningful state. The driver setup and navigation below are deliberately represented by an existing, configured WebDriver named driver; how a driver is created depends on the browser and test setup in your project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • 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
// After navigation and any required wait for the home page state:
Screenshots.save(driver, Path.of("screenshots", "01-home.png"));

// Perform an action, then wait until the results state is ready:
Screenshots.save(driver, Path.of("screenshots", "02-results.png"));

// Continue the test, then save another distinct checkpoint:
Screenshots.save(driver, Path.of("screenshots", "03-confirmation.png"));

Path.of is available in Java 11 and later. For older Java versions, construct paths with Paths.get("screenshots", "01-home.png") and import java.nio.file.Paths.

Use meaningful, collision-resistant filenames

A filename should identify the test and checkpoint, not merely say screenshot.png. For example, use a test-case name plus a numbered step, or include a unique test-run identifier if tests can run in parallel. Otherwise, separate test runs can overwrite one another even when each test’s steps use different names. The helper uses REPLACE_EXISTING, so reusing a destination intentionally replaces its previous image.

For repeatable local review, descriptive deterministic names are convenient. For concurrent or repeated CI runs, include a run-specific directory or identifier. Keep screenshots in the test artifacts directory your build system preserves; writing to a temporary or working directory does not by itself make the image available after a CI job ends.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • 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

Capture at the right point in the test

A screenshot records the state available when the call is made. It does not wait for an application transition on its own. If the test captures immediately after clicking a button, it may get the old page, an intermediate loading state, or an incomplete result.

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. Perform the action. For example, submit a search form or open a dialog.
  2. Wait for the expected state. Use the wait strategy already appropriate for the test, such as waiting for a result element to appear or a loading indicator to disappear.
  3. Capture the checkpoint. Call Screenshots.save once the state being documented is present.
  4. Use another path for the next state. This keeps the earlier checkpoint rather than replacing it.

Prefer a wait tied to the actual condition you care about over a fixed sleep: a fixed delay can be too short on a slow run and unnecessarily long on a fast one. Screenshot calls should document test states; they are not a substitute for assertions that verify those states.

Choose the screenshot output type

Selenium Java’s OutputType API defines three representations. Select one based on how the test will store or consume the image.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • 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.
Output What you receive When it fits Persistence note
FILE A temporary file Copying an image into a test artifact folder The API warns that the temporary file is deleted when the JVM exits. Copy it to a durable destination if you need to keep it.
BYTES Raw image bytes A test framework or storage layer that accepts a byte array Write or upload the bytes to your chosen storage if they must outlive the current process.
BASE64 Base64-encoded image content A report or remote artifact API that expects encoded content Store the encoded value or decode it into an image file if needed.

The example uses FILE because copying a temporary file to a named path is straightforward. If your reporting library accepts byte arrays directly, BYTES can avoid that intermediate copy. Use BASE64 only where the receiving system expects that representation; it is encoded text, not a ready-to-open image file.

Capture an element instead of the driver

Use a driver capture when you want the browser’s screenshot. If the evidence should be limited to a particular HTML element, locate that element and invoke its screenshot method where the driver/browser combination supports it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebElement;

File temporaryElementScreenshot = element.getScreenshotAs(OutputType.FILE);
Files.copy(temporaryElementScreenshot.toPath(),
        Path.of("screenshots", "03-price-card.png"),
        StandardCopyOption.REPLACE_EXISTING);

The TakesScreenshot API documents screenshot capture for drivers and HTML elements, but support can depend on the driver and browser implementation. The Selenium API also notes behavior caveats for implementations that are not W3C-conformant. If element capture fails, confirm support for the exact driver/browser combination; use a driver screenshot if the whole page or browser view is acceptable.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • 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

Common problems and fixes

The screenshot file disappears after the run

OutputType.FILE returns a temporary file, not a permanent artifact path. The Selenium API warns that this file is deleted when the JVM exits. Copy it to a durable path during the test, as the helper does, and configure the CI system to retain that directory if you need the image after the job finishes.

The second image overwrites the first

Both calls used the same destination. Give each checkpoint a distinct filename or directory. If replacement is not intended, remove REPLACE_EXISTING and allow the copy to fail when a file already exists, or generate unique names before saving.

The screenshot is blank or shows the previous state

The capture may have run before the page finished the transition you intended to record. Wait for a page-specific condition before calling the helper. If the condition has already been met, inspect whether the test is using the expected driver and window.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【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.

The test reports a cast or unsupported-operation error

The helper casts the driver to TakesScreenshot. A driver/browser combination that does not support the interface or requested screenshot operation cannot complete that call. Check the API and compatibility for the driver in use; do not assume every non-W3C-conformant implementation behaves identically. For a failure limited to element capture, try a driver capture instead.

Saving fails because the folder does not exist or cannot be written

The helper creates parent directories, but the process still needs filesystem permission to write there. Choose a writable artifact location and check the exception’s destination path. If the destination has no parent component, the helper writes the file in the current working directory.

The images are inconsistent across repeated runs

Different timing, content, viewport, or test data can produce different screenshots. Wait for a defined state, use a predictable test account or fixture where possible, and give each test run its own output directory. The screenshot method captures the state supplied by the running browser; it does not make the page deterministic.

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

Performance, reliability, and artifact handling

Each checkpoint is another browser capture and file operation. Capture the states that help diagnose or document the test rather than taking images after every line of code. A few well-named checkpoints around important transitions are easier to inspect and manage than a directory full of near-identical images.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Keep failures diagnosable: include test and step names in paths so a CI artifact can be traced to the relevant test.
  • Avoid shared-name races: parallel tests should write to separate run/test directories or use unique names.
  • Handle I/O errors: the helper propagates IOException; let the test fail clearly or handle it in the test framework with a message that identifies the destination.
  • Preserve the right files: temporary Selenium files are not a substitute for copied artifacts, and local output is not automatically uploaded or retained by a build server.

Selenium’s project documentation shows the same general capture pattern: obtain a screenshot as a file and copy it to a named destination. See Selenium’s TakeScreenshot documentation.

Or skip the browser setup

If you need a screenshot of a URL rather than a checkpoint from the live WebDriver session, ScreenshotNeo offers a one-request screenshot API. It is a different workflow: Selenium captures the browser state your test has reached, while this request asks the service to load the URL and capture it. See the ScreenshotNeo API documentation for request options.

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

Equivalent Python request:

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)

Equivalent Node.js request:

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 removes supported cookie and consent banners, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Visit ScreenshotNeo to learn more, or sign up for 1,000 free screenshots a month with no card.

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.