Use Selenium’s set_window_size(width, height) to resize the browser, then save_screenshot(path) to save a PNG for each size. Put the dimensions in a list, repeat the resize-and-capture steps, and give every file a width-specific name so one screenshot does not overwrite another. If you need an exact CSS viewport width, measure the page’s actual viewport after resizing: Selenium sets the browser window dimensions, which are not a guarantee of the same dimensions for the page’s content area.
Capture a screenshot at each size with Python
The Selenium Python API provides set_window_size(width, height) to set the current browser window dimensions in pixels and save_screenshot(filename) to save the current window as a PNG. The example below creates an output directory, captures the same URL at three illustrative sizes, checks whether each file was saved successfully, and always closes the browser.
As an Amazon Associate I earn from qualifying purchases.
from pathlib import Path
from selenium import webdriver
url = "https://example.com"
viewports = [(375, 812), (768, 1024), (1280, 900)]
out = Path("screenshots")
out.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
for width, height in viewports:
driver.set_window_size(width, height)
driver.get(url)
ok = driver.save_screenshot(str(out / f"page-{width}x{height}.png"))
if not ok:
raise OSError(f"Could not save screenshot at {width}x{height}")
finally:
driver.quit()
Install Selenium in the Python environment with python -m pip install selenium. This example uses Selenium’s Chrome WebDriver. The dimensions are examples, not a standard device list; replace them with the widths and heights your project needs. The Python API documentation consulted for this guidance is Selenium 4.50.0 documentation.
Recommended Free Tools
Choose dimensions that answer your test question
For desktop responsive-layout checks, choose widths that cover the breakpoints you care about, and set a height that leaves enough page content visible for the comparison. A viewport list can contain any number of width-and-height pairs. The output filename includes both values, which helps distinguish captures even when two runs use the same width at different heights.
#1 Best Overall
- 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
Reload or resize the page already open?
The example navigates to the URL after each resize, making each capture a fresh page load at that browser window size. If your test is specifically about how an already-loaded page responds to resizing, navigate once before the loop and resize for each capture instead. The right choice depends on whether the test concerns initial loading at each size or layout changes after resizing.
Wait for the page state you need
A screenshot can be saved before asynchronous content has reached the state you intend to test. There is no universal page-ready wait that suits every site: choose a condition tied to the page, such as the appearance of a particular element, before calling save_screenshot. For a simple page, navigation followed by capture may be enough; for a page that loads content asynchronously, add an explicit wait for its relevant state. Selenium’s screenshot API documents the capture operation, but does not prescribe one universal wait for every website.
Rank #2
- 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
Check the actual CSS viewport when precision matters
set_window_size controls browser window dimensions in pixels. Do not assume that the requested width equals the rendered page’s CSS viewport width: browser chrome, operating-system behavior, and browser or driver details can affect the content area. After resizing, inspect the page’s effective viewport with JavaScript:
size = driver.execute_script(
"return { width: window.innerWidth, height: window.innerHeight };"
)
print(size)
If the measured content width is not the target, adjust the requested window dimensions and measure again in the environment where the screenshots will run. Keep the requested window size and measured CSS viewport distinct in logs or filenames if exact-width validation is part of your workflow.
Rank #3
- 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.
Use mobile emulation for device-style testing
Resizing a desktop browser window is suitable for ordinary responsive desktop checks. If the test instead requires a Chromium device-style profile, Selenium’s Chromium options support mobile emulation settings that can include screen width, screen height, and pixel ratio. These configure more than a desktop window resize, so select the approach that matches the test: responsive layout at a desktop content width, or rendering under an emulated device profile. Selenium’s JavaScript Options reference includes a custom device-metrics example.
Troubleshoot common capture problems
- Files are missing or overwritten: Confirm the output directory exists and make filenames unique for each size. The example creates the directory and includes width and height in each name.
- The save operation reports failure: Check that the process can write to the output path and that the directory is writable. Treat a
Falsereturn fromsave_screenshotas a failed capture rather than silently continuing. - The screenshot has the wrong content width: Compare the requested window size with
window.innerWidthafter resizing. The window dimensions are not a promise of an exact CSS content viewport. - Content is absent or incomplete: Wait for the page-specific element or state that should appear before capture; a successful navigation alone may not mean asynchronous content is ready.
- The result does not look like a phone rendering: A narrow desktop window and Chromium mobile emulation are different configurations. Use mobile emulation when the test needs a device-style profile, including a pixel ratio.
Or skip the browser setup
For a direct screenshot request without managing a Selenium browser session, ScreenshotNeo accepts a URL and returns an image or PDF. See the ScreenshotNeo API documentation for request options.
Rank #4
- 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
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card required; paid plans start at $5 for 3,000. Sign up for free ScreenshotNeo access.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteFrequently Asked Questions
Can I use a different browser with Selenium for these captures?
Yes. The example uses Chrome, but the resize-and-save loop is based on WebDriver methods. Use the driver for the browser configured in your test environment.
Does `save_screenshot` save a PDF?
No. Selenium’s `save_screenshot` saves the current window as a PNG. The ScreenshotNeo API can return a PDF when that output is needed.
Quick Recap
Best Value
- 【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.
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.




