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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use Selenium’s Firefox WebDriver in headless mode, navigate to the page, wait until the content you need is rendered, then call save_screenshot() for the visible browser area or Firefox’s save_full_page_screenshot() for the whole document. Both save PNG files. For code that needs image data rather than a file, use get_screenshot_as_png() or get_screenshot_as_base64().

Capture a viewport or full page with headless Firefox

Install Selenium and make Firefox available in the environment where the script will run. Then create Firefox options with -headless, start the driver, and take the screenshot only after navigating to the target. This minimal example saves both the current viewport and the full document:

from pathlib import Path
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

output_dir = Path("screenshots").resolve()
output_dir.mkdir(parents=True, exist_ok=True)

options = Options()
options.add_argument("-headless")

driver = webdriver.Firefox(options=options)
try:
    driver.set_window_size(1440, 1000)
    driver.get("https://example.com")

    viewport_path = output_dir / "example-viewport.png"
    if not driver.save_screenshot(str(viewport_path)):
        raise OSError(f"Could not write {viewport_path}")

    full_page_path = output_dir / "example-full-page.png"
    if not driver.save_full_page_screenshot(str(full_page_path)):
        raise OSError(f"Could not write {full_page_path}")
finally:
    driver.quit()

The viewport image reflects the current browser window dimensions and scroll position. The full-page method is a Firefox-specific WebDriver capability for capturing the document beyond the visible area. The Firefox API documents both file methods as PNG output and recommends a full path ending in .png (Selenium Firefox WebDriver API).

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

Install and launch prerequisites

Install Selenium in the same Python environment that will execute the script, and ensure Firefox can be launched there. Selenium’s Firefox driver setup may manage the driver executable, but the browser itself still needs to be available. If the browser cannot start, confirm the Firefox installation and the environment’s permissions before debugging screenshot code.

Headless mode is selected when creating the WebDriver; it is not a screenshot option applied later. A normal screenshot call still captures the browser’s current rendering state whether the browser has a visible window or is running headlessly.

Set a deliberate viewport size

Choose a window size before navigation when screenshots must be repeatable. Different viewport dimensions can change responsive layouts, line wrapping, and which elements are visible. Firefox’s driver supports set_window_size(width, height) and set_window_rect(); the examples use a 1440-by-1000 window, but that is only an example, not a universal standard. See the Firefox WebDriver reference for the documented window methods.

Choose the right screenshot output

Need Method Result Important detail
What is visible in the browser window save_screenshot(path) PNG file Depends on window size and current scroll position.
The complete Firefox document save_full_page_screenshot(path) PNG file Firefox-specific full-document capture; use a .png path.
Image bytes for Python processing or upload get_screenshot_as_png() PNG bytes Does not require an intermediate file.
Text-safe image representation get_screenshot_as_base64() Base64 string Decode it before treating it as image bytes.

The common WebDriver API also offers get_screenshot_as_file(path) for file output. Firefox exposes full-page PNG and base64 methods as well; consult the Firefox API and common WebDriver API for the supported methods.

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

Wait for the page content you actually need

A screenshot records the rendering state at the moment Selenium captures it. A successful navigation does not guarantee that client-rendered text, images, or other delayed content are ready. Use an explicit wait for a meaningful page condition rather than relying on an arbitrary pause. For example, wait until a known element is visible:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
try:
    driver.set_window_size(1440, 1000)
    driver.get("https://example.com")
    WebDriverWait(driver, 20).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
    )
    if not driver.save_screenshot("/absolute/path/example.png"):
        raise OSError("Screenshot file could not be written")
finally:
    driver.quit()

Replace main with a selector that signals readiness for the page you are capturing. A fixed timeout is a maximum wait, not a guarantee that a page is ready after that many seconds. For pages that append content while scrolling, a full-document capture may also depend on when that content is loaded; wait for the relevant content before taking the image.

Save screenshots as PNG bytes or base64

Use the in-memory methods when a downstream Python function accepts binary image data, or when you want to send the result to storage or another service without first writing a file. Firefox documents get_screenshot_as_png() as PNG bytes and get_screenshot_as_base64() as a base64 string.

import base64
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
try:
    driver.get("https://example.com")

    png_bytes = driver.get_screenshot_as_png()
    with open("/absolute/path/example.png", "wb") as image_file:
        image_file.write(png_bytes)

    image_base64 = driver.get_screenshot_as_base64()
    decoded_png = base64.b64decode(image_base64)
finally:
    driver.quit()

Write binary data with wb, not text mode. The base64 value is an encoded representation, not a PNG file by itself; decode it before saving as an image or passing it to a binary-image consumer. The common WebDriver reference documents these byte and base64 methods as well (Selenium WebDriver API).

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

Why Selenium returns False when saving a screenshot

save_screenshot() and Firefox’s full-page file method return a Boolean. A return value of False means Selenium encountered an I/O error while writing the file; it is not a valid image result to ignore. Check the destination before retrying:

  • Create the parent directory before saving; the screenshot method does not create missing directories for you.
  • Use an absolute file path ending in .png, rather than a directory path or an ambiguous relative path.
  • Check that the process has permission to write in the destination directory and that the filesystem is not read-only or out of space.
  • Check the returned Boolean and raise or log an error if it is false.
  • For in-memory output, use get_screenshot_as_png() and write the returned bytes yourself; that separates browser capture from filesystem writing.

The Selenium references describe file screenshots as returning False on an I/O error and recommend full paths (Firefox API; WebDriver API).

Troubleshoot missing, incomplete, or inconsistent captures

The screenshot is blank or missing page content

Capture may have happened before the meaningful page content finished rendering. Wait for a page-specific element or state and confirm the URL loaded as expected. If the page depends on client-side code or delayed assets, an explicit readiness condition is more reliable than taking a screenshot immediately after get().

The image contains only part of the page

save_screenshot() is for the current browser window, not the entire document. Use save_full_page_screenshot() when you need the whole Firefox document. Check the output dimensions and selected method if you are unsure which kind of capture you produced.

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

The screenshot dimensions vary between runs

Set the browser window size explicitly before navigation, especially when the page uses responsive breakpoints. The browser’s current dimensions affect both layout and the area included in viewport screenshots.

The script leaves Firefox processes running

Put browser work inside try/finally and call driver.quit() in the finally block. This releases the headless browser process even if navigation, waiting, or saving raises an exception.

The file method reports failure

Verify the full destination path, .png extension, parent directory, and write permissions. Treat False as a failed save; do not assume that a file exists just because the method returned without raising an exception.

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

Performance, repeatability, and cost considerations

A Selenium screenshot requires starting and controlling a browser, so it is a practical choice when your workflow needs browser automation alongside the capture: interacting with the page, waiting for a particular element, or controlling the browser window. Reuse a deliberate viewport and a content-based wait when comparing captures. Always close the driver, particularly in batch scripts, so browser processes and resources are not left behind.

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.

Screenshot output is local to the browser workflow and is not itself a Selenium usage fee; the relevant operational costs are the compute and runtime of the environment running Firefox and the time spent managing browser sessions. Selenium’s cited API references establish methods and behavior, not capture-speed benchmarks or service-level guarantees, so performance will depend on the page and execution environment.

Or skip the browser setup

If you need a screenshot without installing and managing a browser session, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns an image or PDF. For example, the cURL call below saves a WebP screenshot; see the ScreenshotNeo documentation for parameters and response 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 removes cookie and consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response reports page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents using Claude, Cursor, or another MCP client. The Free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000 shots, and every feature is available on every plan. Sign up for 1,000 free screenshots a month with no card.

Reference notes

The Selenium Project’s Python Firefox WebDriver reference documents viewport and full-page screenshots, along with PNG and base64 output. The common Python WebDriver reference covers the shared file, bytes, and base64 screenshot methods. Neither reference provides named screenshot-performance statistics; the article’s code and behavior descriptions are limited to those documented APIs.

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

Frequently Asked Questions

Can Selenium save a Firefox screenshot as JPEG or WebP?

The documented Selenium screenshot methods described here return PNG files, PNG bytes, or base64-encoded PNG data. Convert the PNG afterward if another image format is required.

Does a full-page Firefox screenshot include content that has not loaded yet?

No screenshot method can include content that is absent from the rendered page at capture time. Wait for the page-specific content you need before taking the screenshot.

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.