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.

Use Selenium’s window-management API: call driver.set_window_size(width, height) before navigating, then verify with driver.get_window_size(). When you also need the window’s screen position, use set_window_rect() and get_window_rect(). The values describe the browser’s outer window, so operating-system window managers, headless mode and remote grids can affect the result.

Set a Selenium window size in Python

Install Selenium and create the driver, set the requested width and height in pixels, then navigate to the page whose responsive behavior you want to test.

from selenium import webdriver

# Selenium Manager can obtain a compatible Chrome driver in current Selenium releases.
driver = webdriver.Chrome()

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

set_window_size(width, height) changes the current window’s width and height. Pass integers; fractional CSS pixels are not accepted by this API. Set the size before navigation when you are testing breakpoints, because the page may choose a layout during its initial load.

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.

Set only the dimensions

driver.set_window_size(1440, 900)

This is the clearest choice when your test contract is simply “run at 1,440 × 900.” It does not intentionally move the window.

#1 Best Overall
Single LCD Computer Monitor Free-Standing Desk Stand Mount Riser for 13 inch to 32 inch screen with Swivel, Height Adjustable, Rotation, Vesa Base Stand Holds One (1) Screen up to 77Lbs(HT05B-001))
  • COMPATIBILITY ☞ Single Computer monitor mount free standing Desk Stand Riser fitting screens for 13,15,17,19,21,23,27,30,32 inch LCD LED Plasma flat screens TV with 50x50mm,75x75mm or 100x100mm backside mounting holes, Includes cable management to keep cords clean and organized
  • ERGONOMIC VIEWING ☞ designed to elevate your monitor to a better viewing angle encouraging better posture for your neck and back while working long desk hours
  • FUNCTIONAL DESIGN☞ Adjustable bracket offers -15°to +10° tilt, -50° to +50° swivel, 360° rotation, and 4 level height adjustment along the center tube. Monitor can be placed in portrait or landscape shapes
  • EASY INSTALLATION – Mounting your monitor is a simple process with an open top slot VESA plate. you can install it within 15 minutes according to the instruction manual, We provide all the necessary tools and hardware for easy assembly
  • SAFETY USE: 1/3" inch Tempered safety glass can bear Maximum weight capacity 77Lbs

Set position and dimensions together

driver.set_window_rect(x=40, y=20, width=1024, height=768)

The rectangle API accepts any combination of x, y, width and height. For example, driver.set_window_rect(width=1000, height=700) changes only the dimensions. Rect commands are the W3C-style interface; older or non-W3C environments may require separate position and size calls.

Check the size Selenium actually applied

Read width and height

size = driver.get_window_size()
print(size)  # {'width': ..., 'height': ...}

assert size["width"] == 1024
assert size["height"] == 768

The returned dictionary represents the current window dimensions. Reading it back catches driver, operating-system and grid behavior that differs from the request.

Read the complete window rectangle

rect = driver.get_window_rect()
print(rect)  # {'x': ..., 'y': ..., 'width': ..., 'height': ...}

assert rect["width"] == 1024
assert rect["height"] == 768

Use a rectangle when a failure could be caused by placement, not just size. Logging x and y is useful when a desktop environment places windows on a different monitor or clamps them to the available work area.

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

Use tolerant verification when the environment is constrained

Exact equality is appropriate for a headed local test when outer-window dimensions are part of the contract. In CI, headless mode and remote execution, assert the requirement your test actually needs and log the returned rectangle:

rect = driver.get_window_rect()
print(f"window rect: {rect}")

# Example: require at least a desktop layout rather than one exact outer size.
assert rect["width"] >= 1000
assert rect["height"] >= 700

If your application responds to the viewport rather than the outer window, verify the layout outcome (for example, which navigation element is visible) instead of assuming that an outer size maps to an identical viewport.

Rank #2
Sale
WALI Computer Monitor Stand for Desk, Adjustable Laptop Riser, up to 44 lbs
  • Design: The monitor stand for the desk has a large 14.6 x 9.3 inches metal shelf that fits most flat screen displays, laptops, and printers, with a maximum support weight of up to 44 lbs (20kg). Rubber pads prevent slipping or damage to your work surface
  • Ergonomic: The height-adjustable monitor riser can raise a computer monitor, notebook, or any device by 3.9 inches, 4.7 inches, or 5.5 inches off the desk to create a comfortable viewing and sitting position which helps reduce stress on the neck and back
  • Ventilated: The computer stand has a large sturdy platform with vented holes, this stand will prevent overheating and keep the device running cool
  • Under-stand Storage: Open space beneath the stand for storing keyboards, notebooks and other desk accessories to reduce desktop clutter
  • Wide Compatibility: Works for single or dual monitor arrangements and laptop setups for home and office desks

A complete, reusable Python test pattern

from selenium import webdriver
from selenium.webdriver.common.by import By

WIDTH, HEIGHT = 1280, 800

driver = webdriver.Chrome()
try:
    driver.set_window_size(WIDTH, HEIGHT)
    driver.get("https://example.com")

    rect = driver.get_window_rect()
    print("Applied window rectangle:", rect)

    # Exact checks are suitable only when this environment honors outer size.
    if rect["width"] != WIDTH or rect["height"] != HEIGHT:
        raise AssertionError(
            f"Requested {WIDTH}x{HEIGHT}, got "
            f"{rect['width']}x{rect['height']}"
        )

    # Continue with page assertions here.
    print(driver.title)
finally:
    driver.quit()

Keep the resize before get(). If a test changes size after loading, wait for the responsive state to settle and then assert page behavior; a resize can trigger media-query changes, reflow and lazy-loading decisions.

Outer window size versus viewport size

Selenium’s window commands target the browser window. Browser chrome, borders, toolbars, display scaling and the operating system’s window manager consume part of that outer rectangle. Consequently, a requested 1024 × 768 window does not guarantee a 1024 × 768 CSS viewport.

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

When viewport dimensions are the real requirement

Responsive tests should define the contract explicitly:

  • Use window commands when the requirement concerns the desktop window managed by the driver.
  • Use a browser’s viewport emulation or a device preset when the requirement is a specific CSS viewport or mobile device profile.
  • Assert visible breakpoints, element geometry or JavaScript-reported viewport values when those are what users experience.

Screen resolution can affect rendering, and the exact behavior of window commands is specific to the individual window manager. This is especially important on Linux CI hosts, containers, headless sessions and Selenium Grid nodes.

Headed, headless and remote execution

Headed local browsers

A visible browser usually gives the most intuitive relationship between requested outer dimensions and returned dimensions. The desktop can still constrain a window if the requested size exceeds the available work area.

Rank #3
Sale
gianotter Dual Monitor Stand Riser With Drawer and 2 Pen Holders
  • 【Ample Storage Space】The dual monitor stand features two magnetic pen holders and a drawer, allowing you to easily organize your desk accessories and office supplies, keeping your workspace clear and tidy for easier access.
  • 【Work with ease】The Gianotter monitor stand for desk can adjust the monitor height to eye level, reducing neck and eye strain, improving posture, and enhancing focus and work efficiency.
  • 【Maximize desktop space】By raising the monitor height, the space underneath the computer stand can be utilized for storing your mouse, keyboard, or other office supplies, maximizing your desktop area.
  • 【No Assembly Required】This monitor riser allows you to skip the hassle of assembly—just unbox it and effortlessly transform cluttered desktop areas, decorating your desktop to enhance your workspace aesthetics!
  • 【Quality Assurance】This desk shelf for monitor is meticulously crafted with a perfect design ratio and high-strength metal materials, ensuring exceptional support performance to easily meet your needs. Whether you're raising your monitor or optimizing your workspace, it's the ideal choice to revitalize your desktop! (USPTO patented product)

Headless browsers

Headless Chrome and other headless implementations may interpret window size as a virtual rendering surface. Configure the headless option supported by your browser when you need deterministic viewport behavior, then use Selenium’s read-back call to confirm what the driver reports. Do not infer a physical monitor size from a headless rectangle.

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

Remote grids and containers

The node, desktop session and driver version—not just your test code—control window management. Record the browser version, platform, requested values and returned rectangle in failure logs. If a grid cannot honor outer-window operations, move the assertion to viewport or page behavior and document that contract.

Equivalent commands in other Selenium bindings

The method names vary by language, but the same distinction applies: set width and height, then read them back; use a rectangle when position is also relevant.

Binding Set size Read size
Java driver.manage().window().setSize(new Dimension(1024, 768)); driver.manage().window().getSize()
Python driver.set_window_size(1024, 768) driver.get_window_size()
C# driver.Manage().Window.Size = new Size(1024, 768); driver.Manage().Window.Size
Ruby driver.manage.window.resize_to(1024, 768) driver.manage.window.size
JavaScript await driver.manage().window().setRect({width: 1024, height: 768}) await driver.manage().window().getRect()
Kotlin driver.manage.window.size = Dimension(1024, 768) driver.manage.window.size

JavaScript’s getRect() returns the rectangle object; a practical check is to assert that its width and height are positive before testing the page.

Troubleshooting common failures

The returned size differs from the requested size

Cause: the window manager, desktop work area, browser chrome, headless implementation or remote node constrained the outer window.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Fix: call get_window_rect() immediately after resizing, log the result and test the actual contract. Reduce the requested size to fit the node, use a configured viewport for responsive tests, or run on a headed environment when outer-window equality is essential.

The command works locally but fails in CI

Cause: CI commonly runs headless or without a full desktop session, and grid nodes can have different display constraints.

Fix: capture browser, driver, operating-system and returned-rectangle details. Avoid hard-coding a physical-screen assumption; assert layout behavior or a minimum usable viewport instead.

The page uses the wrong responsive breakpoint

Cause: you resized after navigation, or the CSS viewport is smaller than the outer window because of browser chrome and scaling.

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

Fix: set size before get(), then verify the breakpoint-dependent element. If the test needs CSS-pixel precision, use viewport/device emulation rather than relying on outer dimensions alone.

Best Value
Sale
WESTREE Dual Monitor Stand Riser, Wood and Steel Multi-Purpose Desktop Storage Stand for 2 Monitors for Computer, Laptop, Printer, TV, Rustic Brown
  • 【Monitor Stand for 2 Monitors】This stand is an ideal choice when you need computers to work together. Unique original design products,this dual-monitor stand features a sturdy construction black with a rustic brown wood finish for an added rustic and unique look.
  • 【Heavy Duty Stand for Computer】Monitor riser is designed with thick solid steel legs, its bearing load is very strong. With anti-slip pads installed on the bottom of the monitor, stable monitor stands without any sliding, you can choose whether to install.
  • 【Multifunctional Monitor Riser 】The monitor stand has powerful storage function of keeping the table clean.It can be used as a monitor stand riser, printer stand, laptop riser, or a TV stand, makeup, animals. Extra storage space underneath organize your office supplies.
  • 【Protect Your Eyes and Neck Health】The ideal ergonomic design is adopted in this unit and has easier operation, you can raise your computer screen to a comfortable sight level, reduce the risk of neck and eye-straining while providing a better viewing experience.
  • 【Easy to Assemble】The board and frame of this monitor stand riser come with pre-drilled holes and all tools, parts and detailed instructions are included in the package, making it very easy to install. Just follow the instructions step by step and every person can do it in 2 minutes.

A rect command is rejected

Cause: an older driver or a non-W3C-compatible implementation may not support the complete rect command.

Fix: update Selenium and the browser driver where possible. Otherwise use the binding’s separate position and size methods, and keep a read-back check.

The browser cannot be created

Cause: Selenium cannot find or start a compatible browser/driver, or the CI user lacks a display.

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

Fix: verify the browser installation and driver compatibility, use Selenium Manager or a pinned driver strategy, and configure the browser’s headless mode for display-less hosts. This is a startup problem, not a window-size assertion problem.

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

Choosing the right API

  • Width and height only: use set_window_size and get_window_size.
  • Position plus dimensions: use set_window_rect and get_window_rect.
  • Responsive CSS behavior: set the size before navigation and assert the resulting UI; do not assume outer and viewport pixels are identical.
  • Remote or headless reliability: log the returned rectangle and use environment-appropriate, contract-based assertions.

Or skip the browser setup

If your goal is a website screenshot rather than interactive browser testing, ScreenshotNeo returns an image or PDF from one request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing result. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools to Claude, Cursor and other MCP clients.

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

See the ScreenshotNeo documentation for parameters and response details. Every plan includes its capture options, including full-page and element shots, custom CSS and JavaScript, waits, blocking rules, headers and cookies, geolocation, PDFs, caching, signed links, asynchronous jobs and bulk capture. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.

Frequently Asked Questions

Should I call set_window_size before or after driver.get()?

Call it before navigation when the test depends on the initial responsive layout. Then read the applied rectangle and assert the page state you care about.

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.

Can Selenium set a mobile viewport with set_window_size alone?

No. It changes the browser window’s outer dimensions. Mobile viewport behavior generally requires a browser or device-emulation configuration in addition to window management.

What does get_window_rect add over get_window_size?

It returns x and y position along with width and height, which helps diagnose window-manager and remote-node constraints.

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.