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

To capture a website screenshot with Java Selenium in Docker, run a Selenium browser container or Grid, connect to it with Java’s RemoteWebDriver, navigate to the page, and save the file returned by TakesScreenshot. Docker determines where the browser runs; the Java screenshot code still captures the current browser context.

Choose where the browser runs

You can run a browser on the same machine as your Java process or send WebDriver commands to a remote browser through Selenium Server/Grid. Grid routes those commands to browser instances and is useful when you need parallel runs or coverage across browser versions and platforms. The Selenium Project describes WebDriver as a W3C Recommendation: WebDriver documentation.

Setup Where the browser runs When it fits
Local WebDriver On the machine running the Java process A direct, individual run without a Grid endpoint
Dockerized RemoteWebDriver/Grid In a container managed by Selenium Grid A repeatable browser environment, remote execution, or parallel and cross-browser work

This guide uses Dockerized Grid. Selenium’s official downloads page links to its Docker repository and browser images; check the current downloads and image tags before choosing versions: Selenium Downloads.

Start a Selenium browser in Docker

For a simple remote arrangement, start a standalone Grid/browser container on the machine that will host it. The Selenium Grid getting-started guide uses http://localhost:4444 as the WebDriver endpoint when the client and Grid share a host. Follow the current instructions in Getting started with Selenium Grid and use an image and tag supported by the official Selenium downloads page.

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.

Keep the Grid endpoint on a trusted network. Selenium warns that an exposed Grid may give outsiders access to Grid infrastructure, internal web applications and files, and the ability to run custom binaries. Apply appropriate firewall restrictions; do not publish an unauthenticated endpoint to the public internet.

Set up the Java client

Add Selenium’s Java binding to your project using your build tool, selecting a current stable Selenium version from the official Downloads page. The version listing changes, so do not treat a version number in an older example as a permanent recommendation. For Grid’s documented quick start, Selenium lists Java 11 or higher; check that requirement when setting up your client: Grid getting started.

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.

The code below uses Apache Commons IO to copy the screenshot file, as in Selenium’s Java screenshot example. Add Commons IO to your project if it is not already available. The browser capability in the Java options must match a browser available in your Grid configuration.

Capture and save a screenshot

This complete example connects to a Chrome-capable Grid at the local default endpoint, sets a repeatable browser window size, navigates to a URL, waits for the page’s document to reach its load event, captures the current browsing context, and writes the image to an explicit path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.
import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class DockerScreenshot {
    public static void main(String[] args) throws Exception {
        String gridUrl = System.getenv().getOrDefault(
            "SELENIUM_GRID_URL", "http://localhost:4444");
        String targetUrl = args.length > 0 ? args[0] : "https://example.com";
        Path output = Path.of("build", "screenshot.png");

        ChromeOptions options = new ChromeOptions();
        WebDriver driver = new RemoteWebDriver(new URL(gridUrl), options);

        try {
            driver.manage().window().setSize(new org.openqa.selenium.Dimension(1440, 1000));
            driver.get(targetUrl);
            new WebDriverWait(driver, Duration.ofSeconds(30)).until(
                d -> "complete".equals(
                    ((org.openqa.selenium.JavascriptExecutor) d)
                        .executeScript("return document.readyState")));

            File screenshot = ((TakesScreenshot) driver)
                .getScreenshotAs(OutputType.FILE);
            Files.createDirectories(output.getParent());
            FileUtils.copyFile(screenshot, output.toFile());
            System.out.println("Saved screenshot to " + output.toAbsolutePath());
        } finally {
            driver.quit();
        }
    }
}

Set SELENIUM_GRID_URL if Grid is not on the same host and port. For example, when the Java client itself runs in a container on a shared Docker network, use the Grid service/container name and port rather than localhost, which refers to the client container. Supply the target URL as the first command-line argument or change the default in the example. The output path is relative to the Java process’s working directory.

Wait for the content you need

document.readyState == "complete" is a useful baseline, but it does not guarantee that a single-page app, delayed image, animation, or API-driven element is ready. If your capture depends on specific content, wait for that element or application state explicitly before calling getScreenshotAs. The page-readiness condition is part of your implementation; Selenium’s basic screenshot example does not promise that dynamic content has finished rendering.

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

Current view versus full page

TakesScreenshot captures the current browsing context. Do not assume this call produces a full-page image. If you need a full-page capture, verify a browser-specific capability or implement and test a scrolling-and-stitching approach for your browser and page; the basic Selenium screenshot API described in the window and tab documentation does not establish full-page behavior.

Make screenshot output repeatable

  • Pin the browser environment: use an explicit Docker image tag rather than a moving latest tag when repeatability matters. Confirm that the tag exists and matches your Grid setup before use.
  • Fix the window dimensions: set the browser window size before navigation or capture. Screen resolution can affect responsive layouts and the resulting image; Selenium documents window sizing alongside screenshot behavior at Working with windows and tabs.
  • Wait for relevant readiness: wait for the content your screenshot depends on, not merely navigation to return.
  • Keep target and output explicit: record the URL, chosen window dimensions, browser image tag, and output path with the run so differences are easier to diagnose.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Driver management and container boundaries

Selenium Manager can configure drivers for supported local browser workflows and is used by Selenium bindings by default for automated driver and browser management. In a remote Grid session, however, the Java client sends commands to the remote browser; a driver installed on the client host does not control the browser inside a separate container. Make sure the Grid browser node has a compatible driver/browser setup and that the requested capability can be matched to an available node. See the Selenium Grid quick start for its driver configuration context: Getting started with Selenium Grid.

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.

Troubleshoot common failures

  • Connection refused at port 4444: Grid is not running, is listening on a different address, or is unreachable from the Java process. Start the container, check its published port and network, and set SELENIUM_GRID_URL to an address reachable from the client.
  • Could not start a session or no matching capabilities: the requested browser is unavailable in Grid, or the node’s browser/image does not match the requested capability. Start a compatible browser node and use the corresponding Selenium options.
  • Works locally but not from a client container: localhost inside the client container is not the Grid container. Put both containers on a reachable network and connect using the Grid service/container name.
  • Screenshot is blank or content is missing: navigation may have completed before the page’s dynamic content. Wait for the specific element or state that must appear, and confirm the requested page loaded successfully.
  • Image dimensions or layout differ between runs: browser size, browser version, responsive breakpoints, or page state may have changed. Fix the window dimensions and use an explicit browser image tag.
  • Output file is missing: the destination is relative to the Java process’s working directory. Check that directory and ensure the process can create the parent path.
  • Grid is unreachable outside the host: a container may publish ports only to a local interface, or a firewall may block the connection. Expose access only to the trusted client network; avoid broad public exposure.

Or skip the browser setup

ScreenshotNeo provides a website screenshot API: one GET request returns a PNG, JPEG, WebP, or PDF. Its clean-shot workflow accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents.

For example, use this cURL request to save a WebP screenshot of a target site:

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

See the ScreenshotNeo API documentation for setup and parameters. One thousand screenshots per month are free with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for the free plan.

Frequently Asked Questions

Can I capture a screenshot from a Selenium Grid session?

Yes. A remote browser session implements Selenium’s screenshot interface; capture it through the WebDriver session with TakesScreenshot.

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.

Does Selenium’s basic screenshot call capture the entire page?

No. It captures the current browsing context; full-page capture requires a separately validated browser-specific or scrolling technique.

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.