October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Capture a Website Screenshot with Java Selenium in Firefox

Use Selenium’s standard screenshot API for Firefox’s current browsing context, or FirefoxDriver’s full-page method for the entire page. Includes Java examples, headless setup, driver discovery, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium’s TakesScreenshot API for a screenshot of Firefox’s current browsing context, or Firefox’s getFullPageScreenshotAs method when you need the entire page. In either case, navigate to the page, save the returned file, and call quit() in a finally block so the browser closes even if capture fails.

Set up Firefox and geckodriver

Install Firefox and make sure Selenium can start it. Selenium’s Firefox guidance specifies Firefox 78 or later for Selenium 4 and recommends the latest geckodriver. Selenium Java bindings look for geckodriver on the process’s PATH; alternatively, set its location with the Java system property webdriver.gecko.driver.

Add Selenium Java using your project’s build system and version policy. The exact dependency version is project-specific; check the Java API documentation for that version if a method signature differs from the examples below.

Set an explicit geckodriver path when needed

For example, pass the property when starting the Java process, replacing the path with the installed executable’s location:

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

java -Dwebdriver.gecko.driver=/path/to/geckodriver CaptureScreenshot

On Windows, use the actual path to geckodriver.exe. If geckodriver is already discoverable on PATH, this property is unnecessary.

Rank #2
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
  • 1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core
  • 4GB DDR4 System Memory; 128GB Solid State Drive
  • 11.6" HD (1366 x 768) Multi-Touch Display
  • Combo headphone/microphone jack - Noble Wedge Lock slot - HDMI; 2 USB 3.1 Gen 1
  • Windows 11 Pro

Capture the current Firefox browsing context

This Java example saves the standard WebDriver screenshot to screenshot.png. It captures the current browsing context—not automatically the full height of a long page.

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

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

public class CaptureScreenshot {
    public static void main(String[] args) throws IOException {
        WebDriver driver = new FirefoxDriver();
        try {
            driver.get("https://www.example.com");

            File screenshot = ((TakesScreenshot) driver)
                    .getScreenshotAs(OutputType.FILE);
            Path destination = Paths.get("screenshot.png");
            Files.copy(screenshot.toPath(), destination,
                    StandardCopyOption.REPLACE_EXISTING);
        } finally {
            driver.quit();
        }
    }
}

The screenshot API returns an image file through Selenium’s Java binding. Replacing an existing destination avoids a copy failure when you rerun the program. quit() closes every window associated with the driver, and the finally block ensures it runs after a navigation, capture, or file-copy error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.

Run Firefox headlessly

For a run without a visible browser window, configure Firefox options before creating the driver:

import org.openqa.selenium.firefox.FirefoxOptions;

FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
WebDriver driver = new FirefoxDriver(options);

Use this in place of new FirefoxDriver() in the complete example; retain the same navigation, capture, and cleanup logic.

Rank #4
15.6 Inch Laptop Computer, N4020, 4GB DDR4 RAM, 128GB eMMC,with Windows 11
  • EFFORTLESS EVERYDAY PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 Home system, delivering reliable, low-power efficiency for daily tasks like document editing, email, online classes, and web browsing
  • 15.6-INCH FULL HD DISPLAY: Enjoy immersive visuals on the 15.6" FHD (1920x1080) anti-glare screen with micro-edge bezels. Delivers clear details and comfortable viewing for long study sessions, working on spreadsheets, and video playback
  • RESPONSIVE MULTITASKING & STORAGE: Built with 4GB LPDDR4 RAM and 128GB eMMC storage for smooth daily essential use. Expand your storage by up to 1TB via the integrated TF card slot to easily store movies, photos, and working files
  • ADVANCED CONNECTIVITY: Outfitted with 2x Full-Featured Type-C ports for data transfer, fast charging, and dual-monitor output, alongside 2x USB 3.2 Gen1 ports and a 3.5mm audio jack for complete peripheral compatibility
  • LIGHTWEIGHT & SILENT OPERATION: Slim and portable for effortless travel or commuting. Features a 1MP HD webcam for remote meetings, 38Wh battery with 45W Type-C fast charging, and a fanless silent design for peaceful work environments.

Capture the full page in Firefox

For a long page, use Firefox’s full-page screenshot API. FirefoxDriver implements HasFullPageScreenshot, which provides getFullPageScreenshotAs. This is distinct from the generic TakesScreenshot.getScreenshotAs call.

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

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class CaptureFullPage {
    public static void main(String[] args) throws IOException {
        FirefoxDriver driver = new FirefoxDriver();
        try {
            driver.get("https://www.example.com");

            File screenshot = driver.getFullPageScreenshotAs(OutputType.FILE);
            Files.copy(screenshot.toPath(), Paths.get("full-page.png"),
                    StandardCopyOption.REPLACE_EXISTING);
        } finally {
            driver.quit();
        }
    }
}

Use the precise Selenium Java API documentation for the dependency version in your project if the method is not available or its signature differs. If you use a remote driver rather than a local FirefoxDriver, follow Selenium’s Remote WebDriver guidance and confirm the remote browser supports the operation you need.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the right screenshot method

Need Use What it captures
What is currently shown in the Firefox browsing context ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE) A standard screenshot of the current browsing context.
The entire page, including content beyond the current view FirefoxDriver.getFullPageScreenshotAs(OutputType.FILE) Firefox’s full-page screenshot facility.

Troubleshoot common failures

  • Firefox will not start: Confirm Firefox is installed and meets the Selenium 4 guide’s minimum of version 78. Check that Selenium can locate geckodriver on PATH, or provide its location with -Dwebdriver.gecko.driver=....
  • The driver cannot be created: Check that the property points to the geckodriver executable itself, not just its containing directory, and that the Java process can access it.
  • The screenshot is shorter than the page: The generic TakesScreenshot call captures the current browsing context. For a full-page image in Firefox, use getFullPageScreenshotAs.
  • The output file is missing: Check the Java process’s working directory and the destination path. Use an absolute path if you need a predictable output location, and ensure the process has permission to write there.
  • The copy fails on a repeat run: A destination file may already exist. The examples use StandardCopyOption.REPLACE_EXISTING so a later capture can replace it.
  • The browser stays open after an error: Put navigation, capture, and saving inside try, with driver.quit() in finally, as shown above.
  • The full-page method is unavailable: Verify that the project uses a Selenium Java version whose Firefox driver API exposes HasFullPageScreenshot and check that version’s API documentation.

Or skip the browser setup

If you need screenshots through an API rather than managing Selenium and Firefox, ScreenshotNeo accepts one GET request with a URL and returns an image or PDF. Its clean-shot steps can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server provides screenshot tools for Claude, Cursor, and other MCP clients.

For example, this cURL request saves a WebP screenshot of Stripe; replace the URL with the page you want to capture. See the ScreenshotNeo API documentation for request options.

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

The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Can I use the standard screenshot call for every Firefox full-page capture?

No. The standard TakesScreenshot method and Firefox’s getFullPageScreenshotAs method serve different capture needs; use the latter when the image must cover the full page.

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

Does the geckodriver property replace installing Firefox?

No. It tells Selenium where to find geckodriver; Firefox must also be installed for a local Firefox session.

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$249.99
Bestseller No. 2
Dell Latitude 3190 11.6' HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core; 4GB DDR4 System Memory; 128GB Solid State Drive
$179.99
Bestseller No. 3
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$304.00

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.