October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix 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 desk3 min

How to Capture a Webpage Screenshot in Selenium with Firefox Headless

Use Selenium’s Firefox WebDriver in headless mode to save a current-window PNG, or choose Firefox’s separate full-page screenshot method for the whole document.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start Firefox in headless mode, navigate to the page, then call Selenium’s save_screenshot() method. That method saves a PNG of the current browser window—not necessarily the whole webpage. Use Firefox’s full-page screenshot method when you need the entire document.

Capture the current Firefox window as a PNG

Install Selenium and make sure Firefox is available on the machine running your script. This example uses Firefox’s -headless option, checks whether the screenshot was saved, and closes the browser even if navigation or file writing fails.

As an Amazon Associate I earn from qualifying purchases.

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

url = "https://example.com"
output_path = "/absolute/path/page.png"

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

driver = webdriver.Firefox(options=options)
try:
    driver.get(url)
    saved = driver.save_screenshot(output_path)
    if not saved:
        raise OSError(f"Could not save screenshot to {output_path}")
finally:
    driver.quit()
  1. Set url to the page you want to capture and output_path to a writable absolute path ending in .png.
  2. Pass Firefox options to webdriver.Firefox so the session starts headless.
  3. Call driver.get(url) before requesting the screenshot.
  4. Check the boolean returned by save_screenshot(); a false result indicates an I/O error.
  5. Call driver.quit() to end the WebDriver session and release browser resources.

The documented Firefox setup uses -headless as a browser argument. Selenium’s Firefox guide says Selenium 4 requires Firefox 78 or greater and recommends the latest geckodriver; compatibility can change, so check the installed versions if Firefox fails to start. Selenium Firefox functionality guide.

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

Current-window screenshots versus full-page screenshots

driver.save_screenshot(path) captures the current window. It does not promise to include document content outside the visible window. Selenium also offers get_screenshot_as_png() when you need the current-window screenshot as bytes instead of writing directly to a file. Firefox’s Python WebDriver API separately provides save_full_page_screenshot(filename) for a full-document capture.

Need Method Result
Visible browser window saved to disk driver.save_screenshot("/absolute/path/page.png") PNG file; returns a boolean indicating whether the save succeeded.
Visible browser window as data driver.get_screenshot_as_png() PNG bytes for code that will process or store the image itself.
Entire document in Firefox driver.save_full_page_screenshot("/absolute/path/page.png") Firefox full-document screenshot saved to a file.

These are distinct capture scopes. Choose the full-document method when content below the current window must appear in the result. See the Selenium Python Firefox WebDriver API for the documented methods and output behavior.

Common problems and fixes

  • Firefox will not start: Confirm Firefox is installed and check the Selenium, Firefox, and geckodriver versions together. Selenium’s Firefox guide specifies Firefox 78+ for Selenium 4 and recommends the latest geckodriver.
  • No screenshot file appears: Use a full, absolute path, ensure its parent directory exists and is writable, use a .png filename, and inspect the boolean returned by save_screenshot().
  • The image cuts off content lower on the page: The basic method captures the current window. Use Firefox’s save_full_page_screenshot() for a full-document image.
  • The screenshot is blank or incomplete: Confirm navigation has occurred before capture. For pages that render content after navigation, the capture may need to wait until the required page content is present; Selenium’s documented workflow captures after navigation. Selenium windows and tabs documentation.
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 returns a screenshot or PDF from one GET request, without requiring you to manage a local Firefox and geckodriver session. Its API accepts a URL and supports PNG, JPEG, WebP, or PDF output; 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://example.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. It also offers an MCP server so AI agents can take screenshots. The Free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000 screenshots. Learn about ScreenshotNeo.

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

Sign up free for 1,000 screenshots a month with no card.

Rank #4
The Web Testing Handbook
  • Used Book in Good Condition

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 *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.