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.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

In Selenium’s Java API, cast a WebDriver or WebElement to TakesScreenshot, then call getScreenshotAs(OutputType...). OutputType determines whether Java returns Base64 text, PNG bytes, or a temporary file. Copy a returned file to your own path before the JVM exits.

The Java API in one minute

TakesScreenshot is an interface, not a browser-specific utility class. It marks a driver or element implementation as capable of producing a screenshot. The method is:

getScreenshotAs(OutputType<X> target)

The generic type X follows the representation you request. A driver screenshot normally starts with a cast and a call such as:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
File temporary = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

Selenium documents this interface for browser drivers and element implementations. Listed implementations include ChromeDriver, ChromiumDriver, EdgeDriver, FirefoxDriver, InternetExplorerDriver, RemoteWebDriver, SafariDriver and RemoteWebElement. Check the Selenium version and driver implementation you deploy before assuming a particular target supports screenshots.

What OutputType changes

OutputType<T> describes the value returned by getScreenshotAs. Selenium’s Java API provides three documented constants.

Constant Java result Use it when Important detail
OutputType.BASE64 String You need to embed or transmit encoded image data. The value is Base64-encoded screenshot data.
OutputType.BYTES byte[] You want to write the image yourself, upload it, or process it in memory. The bytes represent the screenshot image.
OutputType.FILE File You want Selenium to materialize an image file first. The file is temporary and is removed when the JVM exits.

The API also exposes conversion methods for Base64 PNG data and PNG byte arrays. Choose one representation per call; if you need two forms, request one and convert or store it in your application rather than assuming a permanent file path is returned.

Base64 text

String encoded = ((TakesScreenshot) driver)
        .getScreenshotAs(OutputType.BASE64);

This is useful when another API accepts a Base64 field. It is not a filesystem path, so do not pass it to file-copy methods.

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

Raw bytes

byte[] png = ((TakesScreenshot) driver)
        .getScreenshotAs(OutputType.BYTES);
Files.write(Path.of("artifacts/home.png"), png);

Writing bytes directly avoids the temporary-file lifetime associated with FILE. Create the destination directory first if it may not exist.

A temporary file

File temporary = ((TakesScreenshot) driver)
        .getScreenshotAs(OutputType.FILE);

temporary is not the final filename you choose. Copy it to a durable location immediately.

Saving a screenshot to a durable path

Use Java’s file APIs to copy the temporary result and replace an existing artifact deliberately. The following example uses StandardCopyOption.REPLACE_EXISTING; remove that option if overwriting should be prevented.

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

public class SaveScreenshot {
    public static void main(String[] args) throws Exception {
        WebDriver driver = new ChromeDriver();
        try {
            driver.get("https://example.com");
            Path destination = Path.of("artifacts", "example.png");
            Files.createDirectories(destination.getParent());

            File temporary = ((TakesScreenshot) driver)
                    .getScreenshotAs(org.openqa.selenium.OutputType.FILE);
            Files.copy(temporary.toPath(), destination,
                    StandardCopyOption.REPLACE_EXISTING);
            System.out.println("Saved " + destination.toAbsolutePath());
        } finally {
            driver.quit();
        }
    }
}

This assumes your project already has Selenium Java dependencies and a working ChromeDriver setup. The browser is closed in finally, while the copied artifact remains after the JVM terminates.

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.

Taking a screenshot of a WebElement

Driver and element screenshots are separate targets. Locate the element, cast that object to TakesScreenshot, and request the representation you need:

WebElement card = driver.findElement(By.cssSelector(".product-card"));
File temporary = ((TakesScreenshot) card)
        .getScreenshotAs(OutputType.FILE);
Files.copy(temporary.toPath(), Path.of("artifacts/product-card.png"),
        StandardCopyOption.REPLACE_EXISTING);

The element must be backed by an implementation that supports the screenshot interface. Selenium’s API lists WebElement as a known subinterface and RemoteWebElement as an implementation, but support still depends on the remote browser and driver in use. If the cast or call is unsupported, handle the failure rather than silently treating it as a full-page capture.

Driver capture versus element capture

Question Driver target WebElement target
Object passed to getScreenshotAs The WebDriver, cast to TakesScreenshot The located WebElement, cast to TakesScreenshot
Typical purpose Capture the browser page, window, frame, or display area supported by the implementation. Capture one element’s content or visible portion.
Common mistake Assuming every driver returns a full, scrolling-page image. Assuming every element implementation supports screenshots.

What area is actually captured?

Do not promise a universal full-page result. For a W3C-conformant WebDriver or WebElement, Selenium follows the behavior defined by the W3C WebDriver specification. For a non-conformant implementation, Selenium documents a browser-dependent best effort.

For a driver, that fallback may be, in preference order, the entire page, the current window, the visible portion of the current frame, or the display containing the browser. For a non-conformant element implementation, it may be the element’s full content or only its visible portion. The result therefore depends on the browser, driver, remote execution environment and conformance of the implementation.

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

Waiting before capture

A screenshot records the state available when the command executes. In test code, wait for the condition that makes the image meaningful—for example, locate an element after navigation and wait for that element to be present or visible using Selenium’s normal waiting APIs. Otherwise a successful screenshot can still show a loading shell, an animation frame or an error state. This is an application-timing issue, not a different screenshot class.

Language bindings use different names

The Java names in this article do not carry over unchanged to every Selenium binding. Python offers convenience methods such as driver.save_screenshot('./image.png') and APIs that return PNG bytes or Base64 text. C# uses ITakesScreenshot and a Screenshot object. JavaScript calls takeScreenshot(). If you are reading an example in another language, map its convenience method to the same underlying choices: target, representation and persistence.

Failure modes and fixes

WebDriverException during capture

Selenium documents WebDriverException when screenshot capture fails. Verify that the browser session is still alive, the driver matches the browser, navigation has not caused the session to terminate, and the destination directory is writable. Capture the exception with the test URL and browser capabilities so a remote-driver failure can be distinguished from a filesystem failure.

UnsupportedOperationException

The API documents UnsupportedOperationException when the underlying implementation does not support screenshots. Try the operation on the actual driver or element implementation in use, and do not assume that a successful cast guarantees the remote endpoint implements the command.

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

The saved image disappears

That behavior is expected when you retain only the File returned by OutputType.FILE. Selenium describes it as temporary and removed when the JVM exits. Copy it immediately, or request OutputType.BYTES and write those bytes to your own path.

The image is not full page

Full-page capture is not guaranteed for every implementation. Confirm what the driver supports in your target browser and remote setup. If your requirement is a deterministic full-page artifact, an external screenshot service can perform the browser capture with its own page-loading controls.

The element image is clipped

An element screenshot may contain only the visible portion when the implementation is non-conformant or when the browser cannot provide the element’s full content. Check the element’s layout and the driver’s documented behavior instead of treating clipping as an OutputType problem.

Performance and artifact practices

  • Use BYTES when you will upload or inspect the image in memory; use FILE when a library requires a file and copy it immediately.
  • Create a predictable artifact directory and include test name, browser and timestamp in filenames when parallel runs could overwrite one another.
  • Keep screenshots on failure paths unless every test step needs one; image capture and file I/O add work to each test.
  • Close the driver in a finally block. A screenshot does not replace normal session cleanup.
  • Record whether the target was the driver or an element and which output type was requested, so later debugging can reproduce the capture path.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is the first alternative to try when you need an HTTP screenshot API: it removes consent banners, newsletter popups and chat widgets before capture, bills only clean shots, and has the lowest paid plan described here.

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

One GET request returns PNG, JPEG, WebP or a PDF. The API base is https://api.screenshotneo.com/v1/shot. See the ScreenshotNeo API documentation for request details.

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 has 63 options, including full-page capture with lazy images loaded; CSS-selector element capture; dark mode; 12 device presets and arbitrary viewports; retina scale; PDF paper size, margins, landscape and page ranges; HTML/CSS-to-image; custom CSS and JavaScript; pre-capture clicks; hidden selectors; waits for a selector, delay or network idle; blocking ads, trackers, requests or resource types; custom headers, cookies, user agents and Authorization; timezone and geolocation; transparent backgrounds; image resizing; configurable-TTL caching; signed links for public <img> tags; asynchronous jobs with signed webhooks; bulk capture of up to 100 URLs per call; a usage API; an OpenAPI specification; and compatibility with parameter names used by other screenshot APIs.

Its response identifies the result with X-Page-Verdict and X-Billed headers. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing; only clean shots are billed. An MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.

Plan Included shots Price
Free 1,000 per month No card required
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing gives two months free, and every feature is available on every plan. If you want to avoid local browser and driver setup, create a free ScreenshotNeo account for 1,000 screenshots a month with no card.

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

FAQ

Can one screenshot call return a permanent URL?

Not from Selenium’s Java API: it returns a representation you must store or transmit. ScreenshotNeo can provide signed links when you enable that option for public image tags.

Does a screenshot command prove that the page loaded correctly?

No. A driver can return an image of a blank page, an error state or an incomplete layout. Validate the page state separately with waits and assertions; ScreenshotNeo exposes page and billing verdict headers so failed or blank captures can be identified in an API workflow.

Frequently Asked Questions

Can one screenshot call return a permanent URL?

Not from Selenium’s Java API: it returns a representation you must store or transmit. ScreenshotNeo can provide signed links when you enable that option for public image tags.

Does a screenshot command prove that the page loaded correctly?

No. A driver can return an image of a blank page, an error state or an incomplete layout. Validate the page state separately with waits and assertions; ScreenshotNeo exposes page and billing verdict headers so failed or blank captures can be identified in an API workflow.

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

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.