ScreenshotNeo

BlogHow-to

How to Take a Full-Page Screenshot of a Long Webpage with Selenium

Capture a long webpage with Selenium using Firefox’s full-page API, or Chrome’s DevTools protocol. Learn how to wait, save, and troubleshoot the image.

By the ScreenshotNeo team4 October 20267 min read

For a full-document screenshot with Selenium and Python, the simplest documented route is Firefox’s full-page screenshot API:

from selenium import webdriver

url = "https://example.com/long-page"
output = "/tmp/long-page.png"

driver = webdriver.Firefox()
try:
    driver.get(url)
    saved = driver.get_full_page_screenshot_as_file(output)
    if not saved:
        raise OSError(f"Could not save screenshot to {output}")
finally:
    driver.quit()

This captures the full page document rather than just the visible viewport. Selenium’s ordinary WebDriver screenshot endpoint is scoped to the current browsing context, so a full-page requirement needs a browser-specific method. Firefox’s Python driver also provides methods to return the full-page image as PNG bytes or base64. For Chrome, the Chrome DevTools Protocol exposes Page.captureScreenshot with captureBeyondViewport; it defaults to false. [Selenium Firefox API] [Selenium screenshot scope] [Chrome DevTools Protocol Page]

1. Choose the browser-specific full-page method

Setup Method Notes
Python with Firefox get_full_page_screenshot_as_file() Direct Selenium Firefox API for saving a full-page PNG.
Python with Firefox, image in memory get_full_page_screenshot_as_png() or get_full_page_screenshot_as_base64() Useful when the next step consumes bytes or encoded image data.
Chrome and Selenium Chrome DevTools Protocol Page.captureScreenshot Set captureBeyondViewport as needed; ensure your Selenium binding and DevTools protocol version are compatible.
Manual Firefox check :screenshot --fullpage in Firefox Web Console Manual verification only, not a Selenium automation call.

The Firefox methods are documented in the Selenium 4.50.0 Python Firefox API. Mozilla documents the manual Firefox command in its screenshot guide.

2. Capture a full-page screenshot with Python and Firefox

Install Selenium and make sure Firefox is available in the environment. Selenium Manager can manage browser drivers in common setups; follow the current Selenium installation guidance for your environment. The capture itself is a short sequence: start Firefox, navigate, wait for the state your page requires, save the PNG, and close the browser.

from pathlib import Path
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

url = "https://example.com/long-page"
output = Path("artifacts/long-page.png")
output.parent.mkdir(parents=True, exist_ok=True)

driver = webdriver.Firefox()
try:
    driver.get(url)
    WebDriverWait(driver, 20).until(
        lambda browser: browser.execute_script("return document.readyState") == "complete"
    )

    if not driver.get_full_page_screenshot_as_file(str(output)):
        raise OSError(f"Screenshot could not be written to {output}")
finally:
    driver.quit()

print(f"Saved {output}")

The wait for document.readyState is an example, not a universal guarantee that a modern page has finished rendering. If content loads after navigation, wait for a page-specific element or condition before capturing. Selenium’s Firefox API also offers:

png_bytes = driver.get_full_page_screenshot_as_png()
base64_image = driver.get_full_page_screenshot_as_base64()

Use the file method when you want a PNG on disk. Use PNG bytes when passing the result directly to an image-processing library or another service. Use base64 only when the consumer expects encoded image data. The file method returns False on an I/O error; check the return value and verify the destination directory is writable.

3. Capture beyond the viewport with Chrome DevTools

For Chrome, the authoritative parameter is in the Chrome DevTools Protocol’s Page.captureScreenshot method: captureBeyondViewport controls capture beyond the viewport and defaults to false. This is a protocol-level route; the exact Selenium call depends on the Selenium language binding and compatible DevTools protocol version in your project. Do not copy a binding-specific snippet without checking those versions.

Before implementing this route:

  1. Check which Chrome version runs in your environment.
  2. Check the Selenium DevTools integration and protocol version available to that binding.
  3. Call Page.captureScreenshot with captureBeyondViewport enabled when the goal is to include content outside the viewport.
  4. Decode the returned image data and write it as the expected image format.
  5. Inspect the output dimensions and bottom of the document to confirm the capture covers the expected page.

The protocol reference documents the parameter, but compatibility and invocation details depend on your Selenium setup. See the Chrome DevTools Protocol Page documentation.

4. Wait for the right page state

A full-page capture is only useful if the page has rendered the content you need. Navigation completion alone may not mean images, client-rendered sections, or delayed content are ready. Choose a wait condition that matches the page:

  • Known content element: wait until a selector for the main content is visible.
  • Client-rendered page: wait for an application-specific state or element populated by the frontend.
  • Delayed images: wait for the relevant images to load, or scroll through the page when the site loads images lazily.
  • Dynamic page: stabilize the page or capture at a known state so content does not change midway through the operation.

There is no universal wait condition for every site. Lazy loading, infinite scrolling, sticky headers, and page mutations can affect results; validate the output on the actual target page and browser version.

5. Validate the resulting image

After capture, check more than whether a file exists. Open the image or inspect it in your image pipeline and confirm:

  • The top, middle, and bottom sections expected from the document are present.
  • The image dimensions are plausible for the page’s full document height.
  • Important content is not blank because it had not loaded yet.
  • Sticky or fixed elements do not obscure content in a way that makes the result unusable.
  • The file is a readable PNG and the output path is the one your job expects.

For manual Firefox verification, Mozilla documents :screenshot --fullpage in the Web Console. It includes parts of the page outside the window bounds, but it does not replace the automated Selenium call. [Mozilla Firefox screenshot documentation]

6. Common problems and fixes

Symptom Likely cause Fix
Image contains only the visible viewport Used the ordinary WebDriver screenshot endpoint. Use Firefox’s full-page API or the Chrome DevTools Protocol route with beyond-viewport capture.
Firefox method is missing Different browser binding, driver, or Selenium version than the documented Python Firefox API. Confirm the language binding and installed Selenium version, then use the API documented for that exact binding.
Screenshot method returns False File I/O failure, often an invalid path or unavailable directory. Create the parent directory, check permissions and disk space, and use a full filename ending in .png.
Bottom of page is blank or incomplete Content may be lazy-loaded, delayed, or rendered after navigation. Wait for the needed content, and test whether scrolling through the page is required to trigger loading.
Chrome capture does not extend beyond the viewport captureBeyondViewport is false, or the binding/protocol integration differs. Check the protocol parameter and compatibility between Chrome, Selenium, and the DevTools version.
Capture differs between runs The page changes while loading or between captures. Wait for a stable application state and control the relevant page inputs where possible.
Extremely tall capture is slow or unwieldy The full document produces a large image. Consider whether the task needs the whole page as one image; capture sections or the specific content needed when a single huge image is impractical.

7. Performance, reliability, and cost considerations

Full-page images grow with document width and height, so very long pages can take more time to render, encode, transfer, and process than viewport screenshots. Keeping captures to the needed page and output format reduces downstream storage and processing. For repeatable automation, use explicit waits for meaningful content, always close the browser in a finally block, and record the browser and Selenium versions alongside failures.

Selenium requires you to operate the browser and its driver in your environment, so the cost and reliability profile includes that infrastructure and maintenance. This research provides no benchmark or universal timing estimate; measure your own pages and execution environment. Dynamic pages and very tall documents need validation because the cited API references do not guarantee behavior for every lazy-loading or mutation pattern.

Or skip the browser setup

ScreenshotNeo is a website screenshot API: send one GET request with a URL to receive an image or PDF. The API supports full-page capture and loads lazy images. Start with its API documentation.

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

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.com/long-page"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://example.com/long-page'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot. Bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

FAQ

Does Selenium’s normal screenshot call capture an entire long page?

No. The standard WebDriver screenshot endpoint captures the current browsing context; use a browser-specific full-page method when you need the full document.

Can I save the Firefox screenshot as something other than PNG?

The documented full-page file method expects a filename ending in .png. Convert the PNG afterward if another format is required.

Can I use Firefox’s full-page command in a Selenium test?

:screenshot --fullpage is a Firefox Web Console command for manual use. Selenium automation should call the browser API instead.