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

Use Selenium 4 with a current Firefox and geckodriver, enable headless mode with FirefoxOptions.setHeadless(true), navigate with FirefoxDriver, and call getScreenshotAs(OutputType.FILE). Copy the returned temporary file to your destination in a finally-guarded session. For an entire document rather than the visible viewport, keep the concrete FirefoxDriver reference and call getFullPageScreenshotAs(OutputType.FILE).

What you need before writing the test

The examples assume Selenium 4, Firefox 78 or newer, and a current geckodriver, which Selenium recommends for Firefox automation. Add the Selenium Java library to your build with your dependency manager, and make sure the Firefox binary and geckodriver are available to the machine running the test. In CI, install them in the job image or expose their locations through the runner’s normal driver configuration.

  • Selenium: use the Selenium 4 Java API.
  • Firefox: Selenium’s Firefox guidance requires version 78 or newer.
  • geckodriver: keep it current, as recommended in Selenium’s Firefox documentation.
  • Java: the examples use Path.of, so use a Java runtime that provides that API or replace it with your project’s path utility.

Headless mode means Firefox runs without opening a visible window. Selenium exposes this as FirefoxOptions.setHeadless(true); Mozilla also documents the --headless command-line switch.

Take a viewport screenshot and save it as a PNG

This is the smallest complete Java program. TakesScreenshot supplies getScreenshotAs(OutputType<X>); requesting OutputType.FILE gives you a temporary image file that you can copy to a stable path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Logitech K400 Plus Wireless Touch TV Keyboard for PC-Connected TV - Black
  • Media-Friendly: The K400 Plus wireless touch TV keyboard gives you integrated, comfortable control of your PC-to-TV entertainment, eliminating the clutter of a separate keyboard and mouse
  • Plug-and-Play: Simply plug the Unifying receiver into a USB port and the wireless touchpad keyboard is ready to go; adjust controls using the Logitech Options Software to save preferred settings
  • Power-Packed: Built with laid-back control in mind, this wireless TV keyboard has a reliable and long battery life of up to 18 months (2), including an on/off button to help it go even longer
  • Wireless Freedom: Designed for seamless comfort and control, this HTPC keyboard boasts a range of up to 33 ft (1) wireless connectivity, with quiet keys and a large touchpad for easy navigation
  • Broad Compatibility: Designed for use with Windows 7, Windows 8, Windows 10 and later, Android 7 or later, and Chrome OS
import java.io.File;
import java.io.IOException;
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.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

public class HeadlessFirefoxScreenshot {
  public static void main(String[] args) throws IOException {
    FirefoxOptions options = new FirefoxOptions();
    options.setHeadless(true);

    WebDriver driver = new FirefoxDriver(options);
    try {
      driver.get("https://example.com/");
      File captured = ((TakesScreenshot) driver)
          .getScreenshotAs(OutputType.FILE);
      Files.copy(captured.toPath(), Path.of("screenshot.png"),
          StandardCopyOption.REPLACE_EXISTING);
    } finally {
      driver.quit();
    }
  }
}

The file returned by Selenium is managed as a temporary artifact. Copy it before the driver session ends, and choose an extension that matches the image format you request. The default screenshot produced by Firefox is commonly written as PNG; if your pipeline needs a different format, verify the format supported by the Selenium and driver versions you deploy rather than renaming bytes blindly.

Control the browser dimensions

A viewport screenshot contains the current browser viewport, not automatically the whole page. Set the dimensions before navigation so responsive breakpoints, typography, and layout are evaluated at the size you intend to test.

Set the size through WebDriver

import org.openqa.selenium.Dimension;

FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
FirefoxDriver driver = new FirefoxDriver(options);
driver.manage().window().setSize(new Dimension(1440, 900));

Use this approach when the test should express its viewport in Selenium terms. Set the size before get(), then capture after the page reaches the readiness condition your application requires.

Pass Firefox’s window-size argument

FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
options.addArguments("--window-size=1440,900");

Mozilla’s command-line reference defines --window-size width[,height] for screenshot dimensions. The exact argument spelling accepted by your Firefox build is the one shown above; if your environment overrides the browser size, inspect the resulting window dimensions from WebDriver and correct the runner configuration.

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

Wait for the page you actually want to capture

Navigation returning does not prove that lazy images, client-rendered components, fonts, animations, or cross-origin resources are finished. There is no universal Selenium wait that knows when every application is visually complete. Wait for an application-specific signal, such as a loading element disappearing or a results container becoming visible.

Rank #2
WirelessFinest Mini Keyboard Bluetooth + 2.4GHz RF 7-Color Backlit
  • DUAL WIRELESS CONNECTION - BLUETOOTH + 2.4GHZ RF: Easily switch between Bluetooth and 2.4GHz USB receiver modes for flexible connectivity. Enjoy stable, responsive control for Smart TVs, Android TV boxes, PCs, laptops, tablets, and more.
  • BUILT-IN TOUCHPAD & FULL QWERTY KEYBOARD: Navigate, scroll, type, and control your device from the couch with the integrated high-sensitivity touchpad and compact full keyboard layout — no separate mouse needed.
  • 7-COLOR BACKLITS KEYS FOR DAY & NIGHT USE: Adjustable multi-color backlit keyboard makes typing easy in dark rooms, home theaters, bedrooms, or nighttime media setups while adding a modern gaming-style look.
  • WIDE DEVICE COMPATIBILITY: Compatible with most devices supporting Bluetooth or USB receiver connection, including Smart TVs, Android TV boxes, streaming devices, HTPCs, Windows PCs, laptops, Raspberry Pi, tablets, and projectors.
  • GREAT FOR STREAMING, GAMING & HOME THEATER: Perfect for browsing, media streaming, presentations, casual gaming, and controlling your entertainment system from a distance with smooth wireless performance up to 33ft (10m).

Wait for document readiness

import java.time.Duration;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.support.ui.WebDriverWait;

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
wait.until(d -> "complete".equals(
    ((JavascriptExecutor) d).executeScript("return document.readyState")));

This checks the browser’s document lifecycle only. It does not guarantee that an SPA has finished rendering or that below-the-fold images have loaded.

Wait for an application selector

import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import org.openqa.selenium.By;

wait.until(visibilityOfElementLocated(By.cssSelector("main article")));

Choose a selector that represents the finished state of your page. If animations alter the final pixels, wait for the animation’s completion signal or inject test-only CSS to disable motion before capture.

Capture the complete document

For a full-page image, use Firefox’s full-document screenshot support. Keep a FirefoxDriver variable because getFullPageScreenshotAs is exposed by the concrete Firefox driver rather than the generic WebDriver interface.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

public class FullPageFirefoxScreenshot {
  public static void main(String[] args) throws IOException {
    FirefoxOptions options = new FirefoxOptions();
    options.setHeadless(true);

    FirefoxDriver driver = new FirefoxDriver(options);
    try {
      driver.get("https://example.com/");
      File fullPage = driver.getFullPageScreenshotAs(OutputType.FILE);
      Files.copy(fullPage.toPath(), Path.of("full-page.png"),
          StandardCopyOption.REPLACE_EXISTING);
    } finally {
      driver.quit();
    }
  }
}

Use this method when the requirement is the complete document, such as a long article or a visual-regression baseline. A full-page capture can be substantially larger than a viewport image; keep image dimensions and available memory in mind for very long pages.

Choose the output form that fits your pipeline

Requirement Selenium call Useful when
Write an image file getScreenshotAs(OutputType.FILE) You want to copy or archive a file from a test run.
Keep the whole document getFullPageScreenshotAs(OutputType.FILE) You need content beyond the current viewport and are using FirefoxDriver.
Process the result in memory getScreenshotAs with another supported OutputType Your code uploads, hashes, or compares the image without an intermediate path.

The same screenshot API is used for other output types; select the representation your application expects, and still perform the capture only after the page’s readiness conditions are met.

Rank #3
Easytone Backlit Mini Wireless Keyboard with Touchpad Mouse Combo Remote Control with Rechargeable Li-ion Battery and Multimedia Keys for Android TV Box HTPC PS3 Smart TV PC X-Box Linux Windows MacOS
  • 【Easy to Connect & Use】The mini wireles keyboard remote is connected via USB receiver(included) and the work distance up to 10 meters. Just plug and play. very easy to connect and use. Powerful function (keyboard + touchpad + mouse) very perfect for browsing the web, playing games or watching TV.
  • 【Widely Compatibility】The mini keyboard with touchpad can be used for Android TV box, smart TV, PC, Pad, Raspberry PI, PS3, x-box, desktop, laptop, smart phone,HTPC/IPTV, etc. If there is not a USB port, you need to prepare a OTG cable.
  • 【Mutil-Colors Backlit and Rechargeable Battery】The USB mini keyboard has mutil-colors of backlit mode which can clear operate the keys when work at night, don't need to turn on the light which disturbing your families. With auto sleep and wake-up function, and comes with a rechargeable Li-ion battery, it can work for a long time.
  • 【Portable Keyboard】 This small keyboard is designed Small and handheld design, has a innovative shape and petite size, takes up very minimal space in you bag and just makes you say goodbye to chunky keyboard to horizon a new experience of office entertainment anywhere, anytime.
  • 【Sensitive Touchpad & Hotkeys】Wireless mini keyboard with multi-finger touchpad and combo with 8 hotkeys can easy and accurate manipulation. Easy to type and copy / paste, making it faster and more convenient for you browse the page.

Make headless captures reliable in CI

  • Always close the session: put driver.quit() in finally so failures do not leave Firefox and geckodriver processes running.
  • Pin the intended viewport: an unconstrained CI window can produce a different responsive layout from a developer laptop.
  • Use deterministic data: time-dependent banners, randomized content, and network-dependent widgets can change pixels between runs.
  • Wait for the page’s own state: document readiness alone is insufficient for lazy loading and client-side rendering.
  • Keep artifacts on failure: copy the screenshot to the CI artifact directory before teardown when diagnosing a visual mismatch.

Headless execution removes the GUI; it does not remove browser security rules, authentication requirements, or failures caused by an unavailable network resource. Treat those as test-environment concerns and report them separately from an image mismatch.

Troubleshooting common failures

Firefox or geckodriver cannot be started

Check that Firefox is installed, geckodriver is executable and discoverable, and the versions are compatible. Selenium’s Firefox guidance calls for Firefox 78 or newer and recommends the latest geckodriver. In a container, verify the browser binary path and file permissions inside the container rather than only on the host.

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

The screenshot is the wrong size

Set the viewport before navigation using WebDriver’s window-management API or Firefox’s --window-size argument. Confirm the resulting size at runtime; a CI wrapper, desktop environment, or container entrypoint may override it.

The image shows a loading spinner or missing content

Add a wait for the application’s finished selector, image-loading condition, or API-driven state. A fixed sleep can mask a slow run and still be too short on another machine, so prefer an explicit condition with a timeout.

The full-page image is unexpectedly short

Confirm that you called getFullPageScreenshotAs on a FirefoxDriver, not the viewport-only getScreenshotAs method. Capture after the page has expanded and after lazy content that matters to the document has been triggered.

Rank #4
EASYTONE Backlit Mini Wireless Keyboard Touchpad Mouse Combo with Rechargable Li-ion Battery Multi-Media Keys, Handheld Keyboard for Android TV Box, Smart TV, X-Box, PC, Android Windows Linux MacOS
  • ♚【Easy to use】 This wireless keyboard and mouse combo just need to plug the USB receiver into your device and use it. Plug the USB cable to the charging port easily charging (on the top left of the keyboard).
  • ♚【10M Working Range & Portable】This mini keyboard can work up to 10 meters (33 Feet). And the small and handheld design take up very minimal space in your bag. Just let you say goodbye to chunky keyboard to enjoy controlling with the keyboard on the couch. (The range might be affected by the wireless environment)
  • ♚【7-Colors Backlit & Rechargeable Battery 】This backlit keyboard has 7 colors of backlit mode which is easy to use even in dark environments. With auto sleep and wake-up function, and comes with a rechargeable Li-ion battery, it can work for a long time.
  • ♚【Multi-function keyboard】This mini wireless keyboard built-in multi-finger function Touchpad and 8 hotkeys, which can easy to type and copy/paste, making it faster and more convenient for your browse the page.
  • ♚【Widely Compatibility】This mini keyboard mouse combo perfect for PC, Andriod TV Box, Smart TV, x-box, Raspberry PI, TV Box, PS3, HTPC/IPTV, desktop, laptop, etc. If there is not a USB port, you need to prepare a OTG cable.

The run works locally but fails in CI

Compare Firefox and geckodriver versions, viewport settings, environment variables, network access, and file-system permissions. Save the driver log and a failure screenshot. If the page requires authentication, supply the same test credentials and session setup in CI rather than assuming a local browser profile is available.

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.

The output file is missing

Copy the returned temporary file while the driver is alive, use an absolute or known artifact path, and check that the job user can write there. REPLACE_EXISTING prevents an old artifact from hiding a new failure.

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 provides a website screenshot API and MCP server when you need a clean capture without maintaining Firefox, Selenium, and geckodriver. A single GET request returns PNG, JPEG, WebP, or PDF. The API accepts the URL and access key directly:

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}`);

See the ScreenshotNeo API documentation for request options. Before capture, ScreenshotNeo accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

Other options include full-page capture with lazy images loaded, CSS-selector element shots, dark mode, device presets and custom viewports, retina scale, PDF paper and page controls, custom CSS and JavaScript, clicks before capture, selector or network-idle waits, request and resource blocking, custom headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Plan Included shots per month Price
Free 1,000 $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Every feature is available on every plan, and yearly billing gives two months free. Create a free ScreenshotNeo account to get 1,000 screenshots each month with no card; paid plans start at $5 for 3,000 shots.

Best Value
Rii Mini 2.4G Bluetooth Keyboard with Backlit and Touchpad for Smart TV,HTPC
  • Dual Mode 2.4G+BT Mini Keyboard pairs with 2 devices. BT for Smart TV, Tablet, Projector, Android Box, Fire Stick. 2.4G via USB receiver for non-BT devices. Seamless switching.
  • 3-in-1 Mini Keyboard & Touchpad. 33ft range for Smart TV, PC, HTPC, Pi, Steam Deck. Ideal for media & slides. Verify device compatibility before buying
  • 【Backlit Keyboard】 The wireless mini keyboard with White LED backlit is perfect for using in a dark environment
  • 【Long-Lasting & USB-C Rechargeable】Mini usb Keyboard, Stay powered for over 30 days on a single charge with the built-in 500mAh battery. Features modern USB-C charging for quick and convenient power-ups
  • 【Ultra-portable & Compact】Portable bluetooth keyboard, Roughly the size of an iPhone, it's designed for true on-the-go convenience. Perfectly easy to carry around while traveling or commuting

FAQ

Can I debug a failing headless screenshot with a visible browser?

Yes. Temporarily remove setHeadless(true) or set it to false, keep the same viewport and waits, and inspect the page interactively. Restore headless mode for the repeatable CI run.

Does a viewport screenshot prove that the entire page loaded?

No. It records only the current viewport. Content below the fold may still be lazy-loaded, so use an application-specific wait and the Firefox full-page method when the complete document is required.

Why should the variable be typed as FirefoxDriver for a full-page shot?

getFullPageScreenshotAs is documented on Firefox’s full-page screenshot support. A variable declared only as WebDriver does not expose that Firefox-specific method, so retain the concrete driver reference for that call.

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.

Frequently Asked Questions

Can I debug a failing headless screenshot with a visible browser?

Temporarily remove setHeadless(true) or set it to false, keep the same viewport and waits, and inspect the page interactively. Restore headless mode for the repeatable CI run.

Does a viewport screenshot prove that the entire page loaded?

No. It records only the current viewport. Content below the fold may still be lazy-loaded, so use an application-specific wait and the Firefox full-page method when the complete document is required.

Why should the variable be typed as FirefoxDriver for a full-page shot?

getFullPageScreenshotAs is documented on Firefox’s full-page screenshot support. A variable declared only as WebDriver does not expose that Firefox-specific method, so retain the concrete driver reference for that call.

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.

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