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.

Call WebDriver’s screenshot method directly; do not call the window-size setter. In Java, use ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE). In Python, use save_screenshot() or get_screenshot_as_png(). These capture the current browsing context at its existing size.

The direct answer

A Selenium screenshot does not require changing the browser window. Navigate to the page, wait until the state you want is present, and invoke the screenshot API. Leave setSize (Java) or set_window_size (Python) out of the flow.

The Java TakesScreenshot API exposes file and Base64 output. Python’s remote WebDriver API documents file and PNG-byte methods in its screenshot and window methods.

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

Decide what “screenshot” means first

Current-window capture

The ordinary WebDriver screenshot represents the current browsing context/current window. It is not automatically a picture of every pixel in a long, scrollable document. The exact result can depend on the browser and driver’s WebDriver conformance; the Java documentation describes conforming behavior and a browser-dependent best effort for non-conformant implementations.

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Full-document capture

If you need the entire document without enlarging the window, use the explicit full-page method documented for Selenium’s Firefox Python driver: get_full_page_screenshot_as_file() (also available as save_full_page_screenshot() and related PNG/Base64 methods). This is a Firefox-driver API, not a uniform cross-browser guarantee. See the Firefox WebDriver reference.

Window dimensions and page viewport are different

You can read the outer window dimensions before capture without changing them. Java uses driver.manage().window().getSize(); Python uses driver.get_window_size(). Browser chrome, operating-system scaling and a headless execution environment can make those outer dimensions differ from the rendered page viewport. Treat the getter as a measurement, not as a promise about content pixels. Selenium documents getters and setters as separate operations in its windows and tabs guide.

Java: capture the current window in place

This complete example records the reported size, captures the current window, and verifies that the size reported afterward is unchanged. It never invokes setSize.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class InPlaceScreenshot {
    public static void main(String[] args) throws Exception {
        WebDriver driver = new ChromeDriver();
        try {
            driver.get("https://example.com");

            Dimension before = driver.manage().window().getSize();
            File temporary = ((TakesScreenshot) driver)
                    .getScreenshotAs(OutputType.FILE);
            Files.copy(temporary.toPath(), Path.of("shot.png"),
                    StandardCopyOption.REPLACE_EXISTING);

            Dimension after = driver.manage().window().getSize();
            if (!before.equals(after)) {
                throw new IllegalStateException(
                        "The reported window size changed during capture");
            }
        } finally {
            driver.quit();
        }
    }
}

OutputType.FILE gives you a temporary image file to copy. The same API also supports Base64 output when an image must travel as text; choose the form that matches your storage or transport layer.

Keep the size check optional

The before-and-after comparison is a diagnostic, not a prerequisite. If your test only needs an image, call getScreenshotAs directly. If a test has a strict layout requirement, retaining the comparison can reveal an unexpected resize performed elsewhere in setup code, a test fixture or the execution environment.

Python: save a screenshot without calling a size setter

Use save_screenshot() for a file or get_screenshot_as_png() for bytes. Both operate at the current browser state.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
from pathlib import Path
from selenium import webdriver

 driver = webdriver.Chrome()
try:
    driver.get('https://example.com')
    before = driver.get_window_size()

    ok = driver.save_screenshot('shot.png')
    if not ok:
        raise RuntimeError('WebDriver did not save the screenshot')

    after = driver.get_window_size()
    if before != after:
        raise RuntimeError(f'Window size changed: {before} -> {after}')
finally:
    driver.quit()

For in-memory processing, replace the save call with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
png_bytes = driver.get_screenshot_as_png()
Path('shot.png').write_bytes(png_bytes)

Neither example calls driver.set_window_size(). Reading the size with get_window_size() is safe; setting it is a separate operation.

Python Firefox: capture the full document at the existing window size

When “full page” means the complete scrollable document rather than the visible window, use the Firefox-specific method documented by Selenium:

from selenium import webdriver

 driver = webdriver.Firefox()
try:
    driver.get('https://example.com/long-page')
    driver.get_full_page_screenshot_as_file('full-page.png')
finally:
    driver.quit()

This method captures beyond the current viewport without requiring you to enlarge the window. Confirm that your Firefox version and driver expose the method. Do not assume the same full-document call exists with identical behavior in every browser binding.

Choose the API by scope, binding and output

Need Method Binding/driver notes Result form
Visible current window Java getScreenshotAs Generic WebDriver screenshot interface; behavior follows the driver’s WebDriver support. File or Base64 (and other Selenium output types exposed by the binding)
Visible current window Python save_screenshot Remote WebDriver API PNG file
Visible current window in memory Python get_screenshot_as_png Remote WebDriver API PNG bytes
Entire document Python Firefox get_full_page_screenshot_as_file Explicitly documented on the Firefox driver; do not treat as a cross-browser guarantee PNG file (with related full-page byte/Base64 methods documented for Firefox)

Making this distinction before writing assertions prevents a common mistake: comparing a viewport image with an expected full-page artifact.

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

A reliable no-resize workflow

  1. Create the driver with the browser and capabilities your test requires. Do not put a window-size setter in global setup if the original dimensions must be preserved.
  2. Navigate and establish the state to capture. The screenshot records what is rendered at the instant the command runs, so perform the interactions your test requires first.
  3. Read dimensions only if you need an audit trail. Store getSize() or get_window_size(); this does not resize the window.
  4. Invoke the binding’s screenshot operation. Use the current-window method for the viewport, or Firefox’s documented full-page method when the document—not the viewport—is the requirement.
  5. Persist the output immediately. Copy the Java temporary file or write Python PNG bytes to a known path, then close the driver in a finally block.
  6. Record the environment for failures. Keep the browser, driver, binding and reported dimensions with the artifact. Exact output can vary with driver support and execution environment.

Troubleshooting

The image is only the visible portion of the page

That is the normal meaning of a current-window screenshot. If the requirement is the scrollable document, switch to Firefox’s documented full-page API and verify that your Firefox driver supports it. A generic screenshot call does not silently become a full-page capture.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

The window changed even though the screenshot code has no setter

Search setup, fixtures and helper functions for setSize, set_window_size or framework-level viewport configuration. Compare the dimensions immediately before and after capture to identify when the change occurs. Also check whether you are comparing outer window dimensions with content viewport dimensions; browser chrome and headless environments can account for an apparent mismatch.

The Java cast or screenshot call fails

Use a WebDriver implementation and browser driver that expose Selenium’s TakesScreenshot interface, and check the binding and driver versions used by the test. The official Java reference describes the interface and notes that non-conformant implementations may fall back to browser-dependent behavior.

The full-page method is missing in Python

get_full_page_screenshot_as_file is documented on Selenium’s Firefox driver, not as a universal remote-driver method. Use a Firefox WebDriver for that API, or keep the requirement to a current-window screenshot when cross-browser portability is more important than document scope.

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

The file is missing or empty

Check that the destination directory exists and that the test process can write there. In Java, copy the temporary file before the driver is quit. In Python, check the Boolean result from save_screenshot, or write the bytes returned by get_screenshot_as_png() yourself.

The screenshot captures the wrong visual state

Capture only after the navigation and interactions that establish the state under test. If a page is still changing, synchronize your test with its own application conditions before invoking the screenshot; resizing is unrelated to that timing issue.

Performance and reproducibility considerations

Screenshot calls transfer image data from the browser process to the test process, so file output avoids keeping a large PNG in application memory while byte or Base64 output is useful when an API or report requires inline data. Pick one representation consistently for your test artifacts.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Do not infer content dimensions from the outer window getter alone. Store the reported size, browser and driver identity, and capture scope (current window or full document) alongside the image. When a visual diff fails, those fields explain whether the discrepancy is a real page change or a different execution environment.

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

For cross-browser suites, keep the generic current-window API as the portable baseline and isolate Firefox full-page capture in tests that explicitly require it. This avoids treating a driver-specific extension as a universal Selenium feature.

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 is a website screenshot API and MCP server when you need a URL rendered without maintaining Selenium and a browser session. One GET request returns PNG, JPEG, WebP or PDF. The API accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and each response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers.

Here is the one-call cURL form (the ScreenshotNeo documentation has the complete option reference):

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

The equivalent Python request is:

import requests
r = requests.get(
    'https://api.screenshotneo.com/v1/shot',
    params={'access_key': 'YOUR_API_KEY', 'url': 'https://stripe.com'},
    timeout=90,
)
r.raise_for_status()
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}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const image = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', image));

ScreenshotNeo also provides full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and arbitrary viewports, retina scale, PDF paper and page-range controls, custom CSS/JavaScript, clicks, selector or network-idle waits, request and resource blocking, headers, cookies, user agents, Authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, an OpenAPI specification and compatibility with parameter names used by other screenshot APIs. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Plan Included shots Price
Free 1,000 per month No card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Every feature is available on every plan, and yearly billing gives two months free. You get 1,000 screenshots a month free with no card, while paid plans start at $5 for 3,000. Create a free ScreenshotNeo account to try the API.

FAQ

Does a WebDriver screenshot include browser menus and tabs?

The Selenium APIs described here target the current browsing context, not a guaranteed operating-system screenshot of browser chrome. If you need the whole desktop or browser frame, that is outside the WebDriver screenshot contract and requires a different capture layer.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Can I retain the original size and still test responsive layouts?

Yes. Keep the no-resize capture for the existing session, and create a separate driver session whose dimensions are deliberately configured for responsive cases. Separating sessions prevents a responsive test’s setup from changing the artifact you are trying to preserve.

Which artifact should a visual-regression system store?

Store the image in the format your diff tool expects, together with capture scope and the browser/driver environment. A current-window PNG and a Firefox full-page PNG represent different surfaces and should not share one baseline.

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.

Frequently Asked Questions

Does a WebDriver screenshot include browser menus and tabs?

The Selenium APIs target the current browsing context, not a guaranteed operating-system screenshot of browser chrome. Capturing the whole desktop requires a different layer.

Can I retain the original size and still test responsive layouts?

Yes. Keep the no-resize capture in its own session and use a separate, deliberately configured session for responsive cases.

Which artifact should a visual-regression system store?

Store the image format your diff tool expects together with capture scope and browser/driver environment; current-window and full-page images need separate baselines.

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.

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.