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

Set the Selenium browser window dimensions before loading the page, then take the screenshot. In Python, call driver.set_window_size(width, height); for example, driver.set_window_size(1024, 768). The requested window size is not a promise that every browser and operating system will produce the same CSS viewport or image dimensions, so verify the result in the environment where your test runs.

Set a Selenium window size and capture a screenshot

This Python example starts Chrome, requests a 1024-by-768 browser window, loads a page, saves the current-window screenshot, and closes the driver. Replace the example URL and dimensions with the page and size your test needs.

from selenium import webdriver

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)

try:
    driver.set_window_size(1024, 768)
    driver.get("https://example.com")
    driver.save_screenshot("screenshot.png")
finally:
    driver.quit()

The dimensions are expressed as width and height in pixels. The call sets the current WebDriver window; it does not by itself choose a full-document capture mode. Put the size call before navigation when the page’s initial responsive layout needs to load at the target size. If the page changes layout after resizing, set the dimensions before taking the screenshot and wait for the page’s own loading conditions before capturing.

Read back the effective window dimensions

Use get_window_size() to inspect the window size Selenium reports after setting it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
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
driver.set_window_size(1024, 768)
print(driver.get_window_size())
# Example shape: {'width': 1024, 'height': 768}

This is a useful check, but it is not a substitute for checking the page viewport or the saved image when pixel-level layout matters. Browser chrome and the operating system’s window manager can affect the relationship between the requested outer window rectangle and the content area available to the page.

Window size, viewport size, and screenshot size are different

A request such as 1024 × 768 sets browser-window dimensions. Web layouts, however, respond to the CSS viewport, and the screenshot API captures an image of a particular browser area. These dimensions can differ: the browser may reserve part of the window for its interface, and browser or operating-system behavior may change the effective content area. Consequently, a requested window size is not a universal guarantee of either an identical CSS viewport or an output image with precisely those pixel dimensions.

  • Window dimensions: the width and height requested through WebDriver’s window-management API.
  • Viewport dimensions: the page’s visible CSS layout area, which determines responsive breakpoints.
  • Screenshot dimensions and scope: the pixels saved by the screenshot method, which depend on the capture API and browser behavior.

If a test is sensitive to breakpoints or a few pixels of difference, check the effective viewport in the target browser and inspect the actual screenshot artifact. Record the browser, driver, headless or headed mode, and operating-system context alongside visual-test results; that context helps explain differences when a window manager or browser behaves differently.

Choose the right Selenium window-management API

set_window_size is the straightforward choice when you only need to set width and height. Selenium also exposes APIs that can set a window rectangle or provide equivalent window controls in other language bindings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Binding or API Example When to use it
Python: size driver.set_window_size(1024, 768) Set the current window’s width and height.
Python: read size driver.get_window_size() Check the dimensions WebDriver reports.
Python: rectangle driver.set_window_rect(width=1024, height=768) Set size and, optionally, position together. Selenium’s Python API documents this for W3C-compatible browsers; for other browsers it points to separate size and position methods.
Java driver.manage().window().setSize(new Dimension(1024, 768)); Set current-window dimensions in Java.
JavaScript await driver.manage().window().setRect({ width: 1024, height: 768 }); Set the window rectangle in JavaScript.
C# driver.Manage().Window.Size = new Size(1024, 768); Set current-window dimensions in C#.

The language examples show the APIs; they are not a claim that every browser and driver combination implements each operation identically. If the rectangle API is unsupported in the browser you use, prefer the separate size method described for that binding and check the effective result.

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

Capture the current window or the full page

Ordinary Selenium screenshot methods capture the current window. In Python, save_screenshot("screenshot.png") writes that screenshot to a file, while get_screenshot_as_png() returns PNG data. Use the method appropriate to whether your test needs a file or image bytes.

A taller requested window does not, by itself, mean Selenium has captured the entire document. When the requirement is a full-page image, use a full-document capture method explicitly supported by the browser and binding. Firefox’s Python API documents separate full-document screenshot methods. Check the method’s scope and behavior for the browser you run rather than treating an enlarged window as a full-page capture.

Make screenshot dimensions repeatable

Start by defining what the test is comparing. If the purpose is to test responsive rendering, the viewport and its breakpoint behavior matter more than simply requesting a nominal outer-window size. If the purpose is to compare image files, the resulting artifact’s dimensions and capture scope matter too.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Choose a target size. Use the width and height your test requires. Values such as 800 × 600 or 1024 × 768 are examples, not required Selenium sizes.
  2. Set the size on the active window. Do so before page navigation if the initial layout must be evaluated at that size.
  3. Check the effective state. Read the dimensions WebDriver reports and, for sensitive tests, inspect the page viewport in the target environment.
  4. Capture the intended area. Use a current-window screenshot for the visible browser area or an explicitly supported full-document method for a full page.
  5. Inspect and retain the artifact context. Check image dimensions and record browser, driver, execution mode, and operating system with the visual test output.

There is no single cross-browser resolution recipe established for every headless environment. Headless and desktop runs can have different window-management conditions, so a result that is stable on one machine should not be assumed to match another without checking it there.

Troubleshoot common size and capture problems

The page still uses an unexpected responsive breakpoint

Likely cause: The CSS viewport is not the same as the requested outer window dimensions, or the page was loaded before the intended size was set.

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.

Fix: Set the window size before navigation, then inspect the effective viewport in the same browser, driver, and operating-system setup used by the test. Use the viewport—not just the requested window dimensions—as the reference for breakpoint-sensitive assertions.

The screenshot’s pixel dimensions differ from the requested size

Likely cause: The screenshot captures a browser area whose dimensions do not correspond one-to-one with the requested window rectangle. Browser and window-manager behavior can affect the result.

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.

Fix: Inspect the saved image and the reported window size separately. If the test requires exact artifact dimensions, assert or otherwise validate the output image itself in the target environment rather than assuming the requested window dimensions guarantee them.

The window rectangle call fails or is ignored

Likely cause: The browser may not support the rectangle operation through the active WebDriver implementation. Selenium’s Python reference limits its set_window_rect support statement to W3C-compatible browsers.

Fix: Use the binding’s separate window-size method, verify the browser and driver combination, and read back the effective dimensions. If position is also needed, use the separate position method where supported.

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

The capture is missing content lower on the page

Likely cause: The screenshot API captured the current window rather than the full document.

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

Fix: Choose an explicitly documented full-document screenshot method for your browser and binding. Increasing the window height alone does not establish full-page capture.

Visual comparisons differ between local and automated runs

Likely cause: The browser, driver, headless mode, operating system, or window manager differs between the runs, changing the effective viewport or capture.

Fix: Compare the execution context and resulting artifacts, not only the requested dimensions. Keep the browser, driver, and environment consistent where possible, and record those details with the test results.

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

Or skip the browser setup

If you need a screenshot of a URL rather than a Selenium browser session, ScreenshotNeo takes screenshots through a website screenshot API and MCP server. A single GET request can return PNG, JPEG, WebP, or PDF. For a direct Selenium alternative, it avoids setting up browser window dimensions and a local capture flow; it is not a replacement when your test needs to exercise Selenium or validate a specific viewport.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

The API accepts the other screenshot APIs’ parameter names too, which can make switching easier. See the ScreenshotNeo API documentation for available parameters.

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

In Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

In Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Cookie banners and consent overlays are accepted or removed before capture; newsletter popups and chat widgets are also removed. Each of these steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. Response headers identify the page verdict and whether the request was billed.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Every feature is available on every plan.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I use a different size than 1024 × 768?

Yes. Those are illustrative dimensions, not a Selenium requirement; pass the width and height your test needs to the window-size method.

Does a bigger window automatically produce a full-page screenshot?

No. A larger window request does not establish full-document capture; use a full-page method explicitly supported by your browser and binding.

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

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.