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

Use Selenium’s Java API with Chrome’s --headless=new launch argument, wait for the page state you need, then save a TakesScreenshot result to a writable path. Keep Chrome and ChromeDriver on matching major versions, and put driver.quit() in a finally block so the browser session closes even if capture fails.

What you need on the Linux server

  • A Java project with Selenium’s Java API available on its classpath.
  • Chrome or Chromium installed and configured for the server environment.
  • A compatible ChromeDriver. Selenium’s Chrome guidance says Chrome and ChromeDriver should match at the major-version level.
  • A destination directory that exists and is writable by the process running the Java application.

Selenium’s Chrome documentation describes Selenium 4 compatibility with Chrome 75 and greater, but browser and driver releases change. Verify current version guidance when setting up or upgrading rather than treating that historical compatibility note as a guarantee for future releases. See Selenium’s Chrome documentation.

Take and save a screenshot with Selenium Java

This example launches Chrome in headless mode, navigates to a URL, captures the current browser view, and replaces the output file if it already exists. It captures the visible viewport; it does not request a full-page image.

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

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class WebsiteScreenshot {
    public static void main(String[] args) throws Exception {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless=new");

        WebDriver driver = new ChromeDriver(options);
        try {
            driver.get("https://example.com");

            File screenshot = ((TakesScreenshot) driver)
                    .getScreenshotAs(OutputType.FILE);
            Files.copy(
                    screenshot.toPath(),
                    Path.of("/path/to/output.png"),
                    StandardCopyOption.REPLACE_EXISTING
            );
        } finally {
            driver.quit();
        }
    }
}

Replace https://example.com with the target page and /path/to/output.png with a path valid on the server. The Selenium operation getScreenshotAs(OutputType.FILE) returns a temporary file; copy it to the location where your application expects the result. The required file-copy imports are Files, Path, and StandardCopyOption; the other imports are Selenium Java types.

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.

Configure Chrome’s binary when needed

If Chrome is installed somewhere other than Selenium’s expected location, configure its binary explicitly using Chrome options, for example with options.setBinary("/path/to/chrome"). Use the actual executable path on the server. ChromeDriver must also be available to the process; if session creation reports that it cannot locate a browser or driver, confirm the installation and configured paths.

Use a deliberate output path

Choose an absolute path for unattended server jobs so the destination does not depend on the process’s working directory. Create the parent directory as part of deployment or application setup, and ensure the service account can write there. The Selenium screenshot API does not prescribe a universal Linux directory or permission policy.

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.

Wait for the content the image must show

driver.get() normally waits for the page’s load event, but that does not ensure that a dynamic application has finished rendering the content you want. A single-page application, delayed image, or asynchronously populated component may still be changing after navigation returns. Selenium also cautions that document.readyState reaching complete is not proof that dynamic content is ready. See Selenium’s options and page-load documentation.

Use an explicit wait tied to the screenshot’s purpose: for example, wait until a heading is visible, a loading indicator disappears, or a known result is present. This example waits for a target element to become visible before capturing:

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.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

// After driver.get(targetUrl):
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
wait.until(ExpectedConditions.visibilityOfElementLocated(
        By.cssSelector("main .report-ready")
));

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

Replace the CSS selector with an element and condition that genuinely indicate readiness on your page. The timeout is an example, not a universal page-load guarantee. If the required state is not reached within the timeout, the wait fails rather than silently taking a potentially incomplete image.

Run it as a reliable headless Linux job

Headless is a Chrome launch argument

For current Selenium Chrome guidance, add --headless=new through ChromeOptions.addArguments(). The Selenium team says the former headless convenience method was deprecated in Selenium 4.8 and removed in 4.10; Chromium’s newer headless mode became available after Chrome 109 as this argument. Those are historical markers, so use the currently documented argument and recheck guidance when upgrading. See Selenium’s headless-mode history.

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

Always close the session

Call driver.quit() in a finally block or equivalent test teardown. That closes the WebDriver session on success and on exceptions, avoiding orphaned browser processes from failed captures. For a long-running service, create and clean up sessions according to the lifecycle of each job rather than leaving a browser open after a screenshot task finishes.

Local or remote execution

A local ChromeDriver session puts responsibility for browser installation, version alignment, writable storage, and concurrency on the Linux host. A remote WebDriver session moves browser execution to another environment and requires browser-specific options for that remote session. Choose based on who will maintain browser versions, how much concurrency you need, and whether the browser environment can reach the target site. Selenium documents browser options for remote sessions, but no particular hosted provider, price, or service level is established here.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common screenshot failures

Symptom Likely cause What to check or change
ChromeDriver cannot start a session Chrome and ChromeDriver major versions do not match, or the browser executable cannot be found. Compare the installed major versions. Confirm Chrome is installed and, if necessary, set the correct binary path with Chrome options.
The screenshot is missing a chart, image, or page content The capture happened before the relevant dynamic state was ready. Wait explicitly for the element or state that must appear; do not rely only on navigation completion or document.readyState.
No image appears at the requested path The parent directory may not exist, the path may be relative to an unexpected working directory, or the server process may lack write permission. Use an absolute destination, create the directory, and verify write access for the application’s service account.
The capture fails but the browser process remains Cleanup was skipped after an exception. Ensure driver.quit() runs in finally or test teardown.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return a screenshot or PDF; the example below saves a WebP screenshot of the target URL. Read the ScreenshotNeo API documentation for parameters and setup details.

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

ScreenshotNeo accepts cookie or consent banners like a visitor 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, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Does Selenium’s Java screenshot call capture the whole page?

The example captures the browser’s current view. The code does not request a full-page screenshot.

Can I use this approach with a remote WebDriver?

Yes, Selenium supports remote sessions, but configure browser-specific options for the remote session and ensure the remote browser can reach the target site.

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.