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

For browser screenshots in Java, use the automation library already in your project: Playwright Java exposes page, full-page, in-memory, and locator screenshots; Selenium Java exposes screenshots through TakesScreenshot. Neither route is a general desktop-screen capture API: the documented targets are browser pages, drivers, and elements.

Choose the Java screenshot API that fits your project

There is no single Java class called “the Java Screenshot API” that covers every browser automation stack. Playwright and Selenium each provide screenshot methods as part of their Java browser-automation APIs. If your application already uses one, start there; changing frameworks just to save an image adds setup without automatically improving the capture.

Question Playwright Java Selenium Java
What can I capture? A page, the full scrollable page, screenshot bytes, or a locator element. A driver or an element implementing TakesScreenshot; exact behavior depends on driver conformance.
How much output tuning is documented? Format, quality, scale, style injection, animation handling, and timeout options. Select an output type such as a file or Base64; screenshot semantics are delegated to the WebDriver implementation.
When is it a natural fit? Your Java automation already uses Playwright, or you need its documented page and locator options. Your Java automation already uses Selenium and its browser driver supports screenshots.

Playwright’s project repository lists Chromium, Firefox, and WebKit support across Linux, macOS, and Windows. This is not a guarantee that a page renders identically in every engine, operating system, or version; validate the actual browser and driver combinations used in your workflow.

Take a screenshot with Playwright Java

After you have created a Playwright Page and navigated it to the target URL, save a standard screenshot by supplying a path. The following is the documented screenshot call; it assumes page is an already-open Playwright page and Paths is imported from java.nio.file.Paths.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
page.screenshot(new Page.ScreenshotOptions()
    .setPath(Paths.get("screenshot.png")));

Capture the full scrollable page

For a long page, set fullPage on the screenshot options. This captures the full scrollable page rather than only the currently visible viewport.

page.screenshot(new Page.ScreenshotOptions()
    .setPath(Paths.get("full-page.png"))
    .setFullPage(true));

Keep the image in memory

When you want to pass the image to another part of the Java program instead of writing it directly to disk, use the byte-array return value:

byte[] image = page.screenshot();

The returned value is the image data. Your application can then decide whether to store, transmit, or compare those bytes.

Capture one element

Use a locator when the screenshot should contain a particular element—such as a header—rather than the whole page. This also requires a page that has already been navigated.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.locator(".header").screenshot(
    new Locator.ScreenshotOptions()
        .setPath(Paths.get("header.png")));

Locator capture is useful when a full-page image would contain unrelated page content. Choose a selector that identifies the intended element on the site being captured.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Set image format and consistency options

The Playwright Java Page API documents PNG, JPEG, and WebP output. Its documented default format is PNG. Quality does not apply to PNG; JPEG’s documented default quality is 80, and WebP quality 100 is lossless while lower WebP quality settings are lossy. Treat defaults as version-specific: consult the Page API reference for the Playwright version in your project before depending on them.

The API also provides a scale option for CSS-pixel or device-pixel output; the documented default is device scale. If an image is unexpectedly large or differs from a reference, check the selected scale as well as the viewport and browser setup. Screenshot options include a timeout, documented as 30,000 ms by default. A large, slow, or otherwise difficult page can therefore need more time than the default allows.

Playwright also documents style injection and animation controls. These can suppress dynamic elements or make a capture more repeatable, but they change what is shown in the image. Use them deliberately: a test screenshot with animations disabled is not necessarily a faithful record of what a visitor saw.

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

Take a screenshot with Selenium Java

Selenium’s TakesScreenshot interface provides the generic getScreenshotAs method. Cast the driver or element to that interface and choose the desired OutputType. For example, save the driver screenshot as a file:

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

The interface also documents returning Base64 from an element:

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
String screenshotBase64 = ((TakesScreenshot) element)
    .getScreenshotAs(OutputType.BASE64);

The caller chooses the output representation; the API’s driver or element implementation determines the screenshot behavior. Do not assume every browser driver supports every capture operation. Selenium documents that a W3C-conformant WebDriver or WebElement implementation follows the WebDriver specification, while a nonconformant driver uses a browser-dependent best effort. Screenshot support can also be unavailable and raise UnsupportedOperationException.

Make captures useful in tests and pipelines

A screenshot is only a useful comparison when the conditions that shape it are controlled. For a repeatable result, align the viewport, device scale, fonts, animation state, and dynamic page content between captures. Then inspect the actual image produced by the browser and driver combination running in CI; a successful method call does not prove the output matches your expected pixels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Decide whether you need the viewport, the full scrollable document, or one element before choosing the capture call.
  • Keep browser engine, browser version, viewport, scale, and page state consistent for image comparisons.
  • Use style or animation overrides only when a deliberately modified capture is acceptable.
  • For Selenium, verify screenshot support on the driver and element implementation you actually run.

Troubleshoot common screenshot failures

The image is blank or the page is incomplete

The screenshot call captures the page state available at the time it runs. If navigation or rendering is not complete, the image may not contain the content you expect. Ensure your automation reaches the intended page state before calling the screenshot method, then check whether dynamic content is still changing.

The full-page image is unexpectedly large or looks different

Check the requested capture scope and Playwright’s scale option. Device-pixel output can differ in dimensions from CSS-pixel output. Also compare viewport, fonts, animation, and dynamic content across runs; changing style or animation behavior may improve repeatability but can alter the page represented.

Playwright reports a screenshot timeout

The screenshot options document a default timeout of 30,000 ms. Check whether the page or capture is unusually slow and consult the API reference for the version in your project when adjusting timeout behavior.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Selenium reports unsupported screenshot behavior

If the operation raises UnsupportedOperationException, the current implementation does not support that screenshot operation. Verify the driver and target object, and use an implementation that supports the required capture. Selenium’s documented nonconformant-driver behavior is browser-dependent best effort, so changing browser or driver can change the 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.

The screenshot changes between machines

First compare browser engine and version, operating system, viewport, device scale, fonts, and page state. Playwright supports multiple engines, but that alone does not establish pixel-identical output across them. Validate the precise matrix on which the result matters.

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 screenshot over HTTP instead of managing a browser session in Java, ScreenshotNeo is a screenshot API and MCP server for developers. One GET request accepts a URL and returns PNG, JPEG, WebP, or PDF. Its API can also be called from Java HTTP code; the following cURL request shows the same URL-based capture pattern. See the ScreenshotNeo API documentation for request parameters.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie and consent banners are accepted like a visitor and removed, along with known newsletter popups and chat widgets; each of these steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; responses include X-Page-Verdict and X-Billed headers.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; all features are available on every plan.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Cost and usage considerations

With browser automation, your screenshot code runs within the browser workflow you have configured; this article’s cited Playwright and Selenium documentation does not state a per-screenshot service price. ScreenshotNeo’s published plan figures are listed below; yearly billing gives two months free.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Plan Price Included screenshots
Free $0 1,000 per month
Starter $5 3,000
Growth $15 15,000
Pro $39 60,000
Scale $99 250,000
Business $249 1,000,000

For a local test suite, the main practical consideration is consistency and whether your selected driver supports the capture you need. For URL-based service use, the response verdict and billing headers provide information about what happened to a request.

Which Java screenshot method should you use?

Use Playwright’s screenshot API when your Java project already uses Playwright and you need its documented page, full-page, buffer, or locator capture options. Use Selenium’s TakesScreenshot when Selenium is already your automation stack, while verifying support and behavior for the actual driver. For either library, control the conditions that affect the image and validate captures on the browser matrix that matters to you.

Frequently Asked Questions

Can Java screenshot code capture my whole computer screen?

The Playwright and Selenium APIs covered here capture browser pages, drivers, or elements; they are not documented as arbitrary desktop-screen capture APIs.

Does the Selenium screenshot interface guarantee identical output in every browser?

No. Selenium’s documentation distinguishes W3C-conformant implementations from nonconformant drivers, for which behavior is browser-dependent best effort.

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.