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.

In Playwright Java, call page.screenshot(...) to capture a page or locator.screenshot(...) to capture one element. Set a path to save the image, or omit it to receive the screenshot as a byte[]. Use setFullPage(true) for the page’s full scrollable height, and configure masking or animation handling when repeatable captures matter.

Save a screenshot of a page

This minimal example saves the current page as a PNG-named file. It assumes that page is an open Playwright Page; a complete Java program that creates the browser and page appears below.

import java.nio.file.Paths;
import com.microsoft.playwright.Page;

page.screenshot(new Page.ScreenshotOptions()
    .setPath(Paths.get("screenshot.png")));

The screenshot call captures the page at its current state. Navigate to the target URL and wait for any application-specific content that must be visible before taking the shot. A screenshot operation is not a substitute for waiting for a particular element or application state.

Complete standalone example

This example launches Chromium, navigates to a page, saves a screenshot, then closes the browser and Playwright. It requires the Playwright Java library and a compatible browser installation. Add the library using the dependency instructions for the Playwright Java release used by your project; the dependency version and browser-install commands are release-specific.

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.
import java.nio.file.Paths;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

public class PageScreenshot {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().launch();
      try {
        Page page = browser.newPage();
        page.navigate("https://example.com");
        page.screenshot(new Page.ScreenshotOptions()
            .setPath(Paths.get("screenshot.png")));
      } finally {
        browser.close();
      }
    }
  }
}

Replace https://example.com with the page you need to capture. The output path is interpreted by Java as a filesystem path; ensure the process can write to its parent directory.

Capture the full scrollable page

By default, a page screenshot represents the current viewport. To capture the full scrollable page, set setFullPage(true):

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

Playwright describes a full-page screenshot as a capture of the full scrollable page, as if the page had a very tall screen. This is useful for a long article or landing page when you need one tall image rather than a viewport-only capture. Very long pages can produce large image files and take longer to capture or process. If a full-page image is unwieldy, capture a relevant element or use a clip rectangle instead.

Capture one element instead of the whole page

Use a Locator when the output should contain one matched element, such as a header, chart, or product card. Locators can be built from CSS selectors or role-based queries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import java.nio.file.Paths;
import com.microsoft.playwright.Locator;

page.locator(".header").screenshot(
    new Locator.ScreenshotOptions()
        .setPath(Paths.get("header.png")));

page.getByRole(com.microsoft.playwright.options.AriaRole.BUTTON,
    new Page.GetByRoleOptions().setName("Continue"))
    .screenshot(new Locator.ScreenshotOptions()
        .setPath(Paths.get("continue-button.png")));

The first locator uses a CSS class; the second finds a button by its accessible role and name. Prefer a locator that identifies the intended element unambiguously. If a selector matches the wrong content or no content, adjust it before treating the image as a valid capture. Locator screenshots also support screenshot controls such as masking and animation handling.

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.

Keep the screenshot in memory

If a later step will upload, encode, inspect, or compare the image, omit setPath. The call returns image bytes:

byte[] buffer = page.screenshot();

You can pass buffer to code that accepts a byte array, or Base64-encode it for a system that requires text encoding. Keeping bytes in memory avoids writing an intermediate file, but the image still occupies memory; account for that when capturing many large pages in one process.

Choose screenshot options for the job

Page.ScreenshotOptions and Locator.ScreenshotOptions expose controls for the capture area, format, visual stability, and output. The Java API’s exact option names and availability can vary by Playwright release, so check the Java API reference for the version your project uses.

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

Area: full page or clip rectangle

  • setFullPage(true) captures the page’s full scrollable area instead of only the viewport.
  • setClip(new Page.Clip(...)) restricts a page capture to a rectangle. Clip coordinates and dimensions are part of the Page API; use the API reference for the coordinate rules and constructor signature for your installed release.
  • For a single DOM element, a locator screenshot is usually easier to maintain than a manually calculated clip rectangle because the locator identifies the content directly.

Format, quality, scale, and transparency

  • setType(...) selects PNG or JPEG. Playwright’s Java screenshot options select these direct screenshot formats, not WebP.
  • setQuality(...) applies to JPEG. It does not provide a JPEG quality setting for PNG.
  • setScale(...) controls whether the image is sized in CSS pixels or device pixels. Choose based on how the image will be displayed or compared.
  • setOmitBackground(true) omits the default white background to allow transparency; it does not apply to JPEG.

If another system specifically requires WebP, capture in a supported format and convert the resulting image with an image-processing library rather than passing an unsupported type to Playwright.

Mask changing or sensitive regions

Use setMask(List<Locator>) to cover selected regions in the screenshot. This can both obscure content that should not appear in an artifact and reduce visual differences caused by changing values. Use setMaskColor(...) to choose the overlay color. Mask only the parts that are meant to be ignored: masking too much can conceal a genuine layout regression.

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.

Disable animation and hide the caret

Animations can make two captures of the same page differ depending on timing. Set setAnimations(ScreenshotAnimations.DISABLED) to disable CSS animations, transitions, and Web Animations during the capture. Playwright fast-forwards finite animations and cancels infinite animations to their initial state, then resumes them after the screenshot.

setCaret(ScreenshotCaret.HIDE) hides the text caret. Hiding it is the documented default for screenshot APIs, but setting it explicitly can make test intent easier to see. These controls improve consistency; they do not make changing page data, fonts, or external content deterministic by themselves.

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

Set a timeout deliberately

Screenshot options include a timeout. A slow capture may indicate that the page is still changing or that a requested operation cannot complete promptly. Set a timeout appropriate to your test or capture workflow, and investigate why the page is slow rather than increasing the limit without checking the underlying cause.

Use screenshot assertions for visual regression

A saved screenshot is useful for a one-off artifact. A visual regression test instead compares a new screenshot with an expected image and reports a difference. Playwright’s screenshot assertion waits until two consecutive page screenshots produce the same result, then compares the last screenshot with the expectation. That stabilization step is useful for pages that need a moment to settle, but it cannot remove every source of nondeterminism.

Screenshot assertions work only with the Playwright test runner. In Java, use the assertion API exposed by Playwright’s Java test tooling, rather than treating a plain screenshot call as an assertion. The Java assertion equivalent is available through the test tooling; consult the API reference for the installed release for its exact method and options.

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

Before adopting a visual baseline, decide what should count as a meaningful change. Configure full-page capture, clipping, masking, animation handling, and any supported diff thresholds to fit the page. Keep the browser, viewport, page state, and test data consistent between baseline creation and later runs. A threshold that is too strict can flag harmless rendering variation; one that is too permissive can allow unwanted changes through.

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

Choose the right capture approach

Need Use Trade-off
Save a page image once page.screenshot with setPath Writes a file that the process must be able to create.
Send an image to another step in code page.screenshot() returning byte[] Avoids an intermediate file but keeps image data in memory.
Capture a component or control locator.screenshot Requires a locator that identifies the intended element.
Capture the entire document height Page screenshot with setFullPage(true) Can yield a very tall, large image.
Check for visual changes in a test Screenshot assertion in the Playwright test runner Requires test-runner setup and deliberate baseline/stability choices.

There is no authoritative performance benchmark in the cited Playwright material for Java screenshot calls. Capture time and file size depend on the page and capture settings, so measure your own workload if throughput matters. For reliable output, use explicit navigation and page-state waits, stable test data, a consistent viewport, and masks for genuinely volatile areas.

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

Troubleshoot common screenshot problems

The file is missing or cannot be written

Check that setPath points to the location you expect and that the Java process has permission to write there. Use an absolute path while debugging if the current working directory is unclear. If you omitted setPath, the API returns bytes instead of saving a file.

The screenshot contains only the visible viewport

Set setFullPage(true) on the page screenshot when you need the full scrollable page. A locator screenshot is scoped to the element, not the entire document.

The element capture is wrong or empty

Inspect the locator and verify it identifies the intended element in the page state being captured. Prefer an accessible role and name when appropriate, or refine the CSS selector. If the desired content appears after navigation or an application update, wait for that content using a selector or another explicit condition before calling screenshot.

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.

The visual test fails intermittently

Look for animations, a visible caret, changing timestamps, rotating content, or other variable regions. Disable animations and mask only those regions whose differences are expected. Also check that the test uses consistent data and capture dimensions. Do not raise a diff threshold until you understand which differences are being accepted.

The image has an unexpected format or background

Choose PNG or JPEG explicitly with the screenshot type option when that distinction matters. Quality applies to JPEG; transparent background is available with setOmitBackground(true) except for JPEG. If a consumer expects WebP, convert after capture.

The capture takes too long

Check that the page has reached the state your workflow intends to capture and review the screenshot timeout. Full-page capture and large assets may require more work than a small viewport or element capture. The Playwright material cited here does not establish a fixed capture-time guarantee.

Or skip the browser setup

If you need a screenshot endpoint rather than managing a Java browser process, ScreenshotNeo can return a PNG, JPEG, WebP, or PDF from one GET request. See the ScreenshotNeo API documentation for request options.

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://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides screenshot tools for AI agents, including 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.

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

Frequently Asked Questions

Can Playwright Java save a screenshot as WebP directly?

The Java screenshot options described here select PNG or JPEG. If you need WebP, capture a supported format and convert the image afterward.

Do screenshot assertions work in an ordinary Java application?

No. Playwright’s screenshot assertions require the Playwright test runner; use a regular screenshot call for a standalone capture.

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.

Can I capture only part of a page without selecting an element?

Yes. A page screenshot can use a clip rectangle. Check the Page API reference for the coordinate and dimension details in your Playwright Java release.

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.