Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober 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 Now×
Skip to content
Browser Testing

How to Resize a Web Page in Selenium to Capture a Full-Page Screenshot

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.

To resize a page for a Selenium screenshot, set the browser window to the viewport width and height you need, then use the screenshot method supported by your WebDriver. In Python, driver.set_window_size(1366, 900) establishes a 1366×900 rendering condition. A normal save_screenshot() captures only that current window. Firefox WebDriver also provides a true full-document method, save_full_page_screenshot(), which includes content below the visible viewport.

Window size and document height solve different problems: the width selects the responsive layout, while a full-page method captures content outside the visible window. The workflow below covers viewport shots, Firefox full-page captures, Chrome-compatible fallbacks, internal scroll areas, dynamic pages, and a browser-free API option.

What “resize” means in Selenium

Selenium’s window commands change the browser’s outer dimensions and, consequently, the viewport used to render the page. That affects CSS breakpoints, responsive navigation, image sizing and any JavaScript that reads viewport dimensions. It does not automatically make a normal screenshot include the entire document.

Choose dimensions that represent the condition you want to document or test. For example, 1366×900 is a common desktop condition; a narrower width can deliberately exercise a tablet or mobile breakpoint. Do not assume that a wider window simply scales the desktop page. Responsive sites may switch layouts, hide controls, or load different markup at a new width.

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

Window size versus viewport size

set_window_size(width, height) requests the browser window dimensions. Browser chrome, operating-system scaling and headless-mode behavior can make the actual CSS viewport slightly different. If exact CSS dimensions matter, read window.innerWidth and window.innerHeight with JavaScript after resizing and record those values with the screenshot.

Python: resize and capture the visible viewport

Use save_screenshot() when the required output is exactly what a user sees in the current browser window.

from selenium import webdriver

options = webdriver.FirefoxOptions()
# options.add_argument("-headless")
driver = webdriver.Firefox(options=options)

try:
    driver.set_window_size(1366, 900)
    driver.get("https://example.com")
    driver.save_screenshot("viewport.png")
finally:
    driver.quit()

The navigation occurs after resizing so that the initial responsive layout is calculated at the intended width. If your application changes layout after login or after a route transition, resize before each state you want to capture and wait for that state to finish rendering.

Using set_window_rect()

Where the driver supports it, set_window_rect(width=1366, height=900) expresses the same intent and can set position as well. A complete example is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
driver.set_window_rect(x=0, y=0, width=1366, height=900)

Keep the width and height explicit in test code. A maximized window is not a reproducible viewport because it varies with monitor resolution, operating-system scaling and the machine running the test.

Firefox: capture the full document directly

Firefox WebDriver exposes first-class full-page screenshot methods. They capture the document beyond the current window bounds instead of requiring you to scroll and compose images.

from selenium import webdriver

options = webdriver.FirefoxOptions()
# options.add_argument("-headless")
driver = webdriver.Firefox(options=options)

try:
    driver.set_window_size(1366, 900)
    driver.get("https://example.com")
    driver.save_full_page_screenshot("page.png")
finally:
    driver.quit()

The related Firefox API names are get_full_page_screenshot_as_file(), save_full_page_screenshot(), get_full_page_screenshot_as_png() and get_full_page_screenshot_as_base64(). Use the file method for a straightforward artifact, PNG bytes when another Python component will process the image, or base64 when the result must travel through a text-oriented channel.

Viewport and full-page outputs in one run

from selenium import webdriver

options = webdriver.FirefoxOptions()
driver = webdriver.Firefox(options=options)

try:
    driver.set_window_size(1366, 900)
    driver.get("https://example.com")
    driver.save_screenshot("viewport.png")
    driver.save_full_page_screenshot("full-document.png")
finally:
    driver.quit()

Both images use the same responsive width. The first represents the visible window; the second represents the entire document as implemented by Firefox’s full-page capture.

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

Chrome and other drivers: choose a full-page strategy

Selenium’s common screenshot commands—save_screenshot(), get_screenshot_as_file() and get_screenshot_as_png()—capture the current window. Resize first to establish the desired responsive condition, then use a browser-native full-page capability if your chosen driver exposes one, or build a page-specific capture-and-stitch workflow.

Scroll-and-stitch fallback

A stitching fallback captures viewport-sized slices while scrolling, then composes them in an image library. It is not a universal Selenium guarantee: fixed headers, sticky navigation, changing lazy content and fractional scroll positions can create overlaps or gaps. The outline below shows the engineering decisions your implementation must make.

  1. Navigate and wait until the page’s initial content is ready.
  2. Read document height and viewport height with JavaScript.
  3. Scroll in increments close to one viewport height, retaining a deliberate overlap.
  4. Capture each slice with save_screenshot().
  5. Remove the overlap when composing slices, accounting for any fixed or sticky element that repeats.
  6. Capture the bottom position explicitly; the final scroll offset is often less than the document height minus one viewport.
  7. Validate the composed image against the live page at several boundaries.

Do not treat a large window height as a substitute for this logic. It can reduce the number of slices, but it does not address content inside a nested scrolling element or guarantee that lazy sections have loaded.

Make dynamic pages stable before capture

Full-page images are only useful when the page is in a known state. Add waits for the condition that matters to your page rather than relying on a fixed sleep.

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

Wait for a key element

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

wait = WebDriverWait(driver, 30)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "main")))

For a route that renders asynchronously, wait for a page-specific heading, table, chart container or “loaded” marker. A visible shell is not proof that images, fonts or data have finished.

Lazy-loaded images

Some pages request images only after they approach the viewport. A full-document API may trigger or include them differently from a manual scroll. If an image is missing, scroll through the page before capture, wait for its complete state, or use the page’s own “load more” control. Confirm the result visually; Selenium does not promise that every lazy-loading implementation behaves identically.

Animations and transitions

Animations can produce inconsistent captures. Where your test permits, inject temporary CSS to disable transitions and animations, or wait for a stable state. Do not disable motion when the motion itself is what you are documenting.

driver.execute_script("""
const style = document.createElement('style');
style.textContent = `*, *::before, *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}`;
document.head.appendChild(style);
""")

Internal scroll containers need separate handling

A page can have a short document with a tall panel such as <div class="results"> that owns its own scrollbar. A document-level full-page screenshot will not necessarily include the panel’s hidden rows. Identify the element and inspect its scrollHeight and clientHeight.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
panel = driver.find_element("css selector", ".results")
height = driver.execute_script("return arguments[0].scrollHeight", panel)
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", panel)

For a single element, temporarily setting its height to its scroll height may expose all content, but that changes layout and can invalidate the screenshot. A safer approach is to capture the panel in slices, restore its original styles, and clearly document that the result is a composed image rather than a native document capture.

Fixed and sticky elements

Headers with position: fixed or position: sticky can appear repeatedly in stitched screenshots or cover content while you scroll. Before stitching, decide whether the header should appear once, at every viewport slice, or not at all. You can hide it temporarily with a page-specific selector, but that produces an image different from the unmodified page. Whichever policy you choose, apply it consistently and inspect overlap boundaries.

Very tall documents and practical limits

Full-page images can become extremely large in pixel dimensions and memory use. A long page at a high device scale factor may exceed image-library or browser limits even when the HTML loads normally. Split exceptionally long captures into sections, reduce the scale factor, or produce a PDF when a single raster image is not a useful artifact. The exact practical limit depends on the browser, operating system, graphics backend and page.

Diagnose a screenshot that is only the viewport

The file ends at the fold

You used save_screenshot(), which is a current-window command. On Firefox, switch to save_full_page_screenshot(). On drivers without that method, implement and test a native full-page capability or a stitching workflow.

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 width looks wrong

The window was resized after navigation, the driver ignored the requested dimensions, or the page changed breakpoint after a route transition. Resize before navigation, read window.innerWidth, and verify the actual layout condition in the captured image.

Sections are blank

Content may be lazy-loaded, blocked by an authentication state, or still waiting on network data. Wait for a page-specific element, scroll through lazy regions, check browser-console and network errors, and capture only after the required content is present.

Content is duplicated in a stitched image

Your slices overlap, or a sticky element was painted in each slice. Use a measured overlap, calculate the crop from actual scroll offsets, and handle fixed elements separately. Never assume that the CSS viewport height equals the number of new pixels added after a scroll.

A nested panel is incomplete

The panel—not the document—owns the scroll. Capture that element independently or expand it in a controlled, reversible test state.

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

Headless and headed results differ

Headless mode can use different window-management behavior, fonts or available screen dimensions. Record the mode, requested size and measured CSS viewport in test output, and compare like with like.

Reproducibility, reliability and cost considerations

  • Pin the environment: Keep browser, WebDriver, operating-system image and installed fonts consistent for visual regression work.
  • Record capture conditions: Save URL, window request, measured viewport, browser mode, device scale factor and timestamp with the image.
  • Wait on states, not guesses: A targeted explicit wait is usually more reliable than a long fixed delay.
  • Control volatile content: Ads, rotating banners, clocks and personalized recommendations can make two otherwise identical captures differ.
  • Review artifacts: Always inspect full-page boundaries, lazy images and overlays; a successful WebDriver command only proves that bytes were returned.
  • Plan storage: Large PNGs consume considerably more storage and memory than compressed JPEG or WebP outputs. Choose the format according to whether pixel fidelity or file size matters.
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. One GET request returns a PNG, JPEG, WebP or PDF. It accepts the page’s cookie or consent banner before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, 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.

For the full parameter list and authentication details, see the ScreenshotNeo documentation.

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

ScreenshotNeo also supports full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets or custom viewports, retina scale, custom CSS and JavaScript, clicks before capture, selector or network-idle waits, request blocking, headers and cookies, user-agent and authorization values, 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, usage reporting and an OpenAPI specification. Its parameter names are compatible with those used by many other screenshot APIs, which can simplify migration.

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

An MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients. Plans include 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 screenshots, and every feature is available on every plan. Create a free ScreenshotNeo account to get started.

Frequently Asked Questions

Can I use a mobile device width with Selenium?

Yes. Set a narrow window width that matches the responsive condition you want to test, then verify the measured CSS viewport because browser chrome and scaling can affect the final value.

Does a full-page screenshot include content in an iframe?

The iframe is a separate browsing context. Whether its content appears depends on how the browser capture handles that context; test the specific page and permissions rather than assuming document-level behavior.

Should I save PNG or JPEG?

PNG preserves text and sharp UI edges without lossy compression. JPEG is often smaller for photographic pages but can introduce artifacts around fine text; choose based on the downstream comparison or delivery requirement.

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

Why does my screenshot contain a cookie dialog?

Selenium captures the page as rendered. Accept or hide the dialog in your test setup, or use a capture service that performs consent handling before 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.

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.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.