ScreenshotNeo

BlogHow-to

How to Capture a Webpage Screenshot with Selenium in Landscape Orientation

Set Selenium’s browser window to landscape dimensions, then save a PNG. This guide covers sizing, full-page capture, troubleshooting, and a browser-free API option.

By the ScreenshotNeo team4 October 20267 min read

To capture a webpage screenshot with Selenium in landscape orientation, set the browser window width greater than its height before navigating and saving the screenshot. Selenium’s ordinary screenshot methods capture the current browser window as a PNG.

from selenium import webdriver

url = "https://example.com"
driver = webdriver.Chrome()
try:
    driver.set_window_size(1365, 768)  # width, height; width > height
    driver.get(url)
    driver.save_screenshot("page.png")
finally:
    driver.quit()

1365 × 768 is an example, not a required Selenium size. Choose dimensions for the layout you need and check the result in the browser and execution environment where the capture will run. Selenium documents both window sizing and screenshot methods in its Python WebDriver API.

1. What “landscape screenshot” means

For a browser-window capture, landscape means the configured width is larger than the height. Selenium sizes the browser window; the page then lays itself out in response to the available space. A landscape window does not guarantee that every site will look the same: responsive breakpoints, browser chrome, display resolution, and the driver environment can affect the rendered page. Selenium’s window guide notes that screen resolution can affect rendering.

The normal screenshot is the currently visible browser window. This is different from capturing the entire document, which may be much taller than the viewport. It is also different from printing a landscape PDF: Selenium’s PDF print orientation setting applies to PDF output, not to a PNG screenshot.

2. Set a landscape window and save a PNG

Prerequisites

  • Python and Selenium installed in your environment.
  • A browser and compatible WebDriver setup for the browser you use.
  • A destination path where the process can write the PNG file.

Install Selenium with python -m pip install selenium if it is not already installed. Then save this as capture_landscape.py and run it with Python:

from pathlib import Path
from selenium import webdriver

url = "https://example.com"
output = Path("page-landscape.png")

options = webdriver.ChromeOptions()
# Uncomment for a headless run if supported by your installed browser:
# options.add_argument("--headless")

driver = webdriver.Chrome(options=options)
try:
    driver.set_window_size(1365, 768)
    driver.get(url)

    # Add a wait here if the page needs time or a specific element to load.
    saved = driver.get_screenshot_as_file(str(output))
    if not saved:
        raise OSError(f"Could not save screenshot to {output.resolve()}")
    print(f"Saved {output.resolve()}")
finally:
    driver.quit()

The order matters: configure the dimensions before capturing, navigate to the target, wait for the content you need, and then save. The API also provides save_screenshot(path); get_screenshot_as_file(path) returns False for an I/O failure and expects a PNG filename.

Use a window rectangle when you need position too

set_window_size(width, height) is usually the clearest choice when only dimensions matter. Selenium also exposes set_window_rect for setting position and size together, and get_window_rect() for inspecting the resulting rectangle:

driver.set_window_rect(x=0, y=0, width=1365, height=768)
print(driver.get_window_rect())

The requested dimensions describe the browser window. If the exact page viewport dimensions matter, inspect the rendered page in your target browser and environment rather than assuming the window and content viewport are identical.

3. Choose dimensions for the page

Pick a width and height that produce the layout you intend to document or test. A wider window can move a responsive site from a mobile or tablet breakpoint to a desktop breakpoint. The example 1365 × 768 is just one landscape-shaped size.

  • Use the same dimensions across runs if you need comparable screenshots.
  • Choose a wider ratio when the goal is to show a broad table, dashboard, or navigation layout.
  • Keep the height large enough to include the content that should be visible without scrolling.
  • Verify the saved PNG on the same browser and driver configuration used in deployment or CI.

4. Wait for the page state you want

Navigation completing does not necessarily mean every image, animation, or client-rendered component is ready for capture. For a stable screenshot, wait for a page-specific condition, such as the presence of a result element, before saving. Here is a reusable pattern with an explicit wait:

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

url = "https://example.com"
driver = webdriver.Chrome()
try:
    driver.set_window_size(1365, 768)
    driver.get(url)
    WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "main"))
    )
    driver.save_screenshot("page.png")
finally:
    driver.quit()

Replace main with a selector that indicates the content you actually need. A fixed sleep may be useful for a known short animation, but it can waste time on fast runs and still be too short on slow ones.

5. Current window, full document, and PDF are different outputs

Need Approach Scope
Landscape PNG of what is currently visible Set a wide window, then use save_screenshot or get_screenshot_as_file Current window capture
Full tall page in one image Use a browser-specific full-document capability where available Not the same as the ordinary window screenshot
Landscape PDF Use Selenium’s PDF printing workflow and set print orientation PDF document output, not a rotated PNG capture

The Selenium Firefox Python API documents full-document methods such as get_full_page_screenshot_as_file. The cited API evidence is Firefox-specific; do not assume that method is portable to every browser. See the Firefox WebDriver API. For an ordinary landscape screenshot, set the window dimensions and capture the current window.

6. Return screenshot bytes or base64 instead of a file

If another part of your program needs the image in memory, Selenium’s Python API can return screenshot bytes or a base64 representation. For example, write the bytes yourself:

png_bytes = driver.get_screenshot_as_png()
with open("page.png", "wb") as image_file:
    image_file.write(png_bytes)

For base64 output, use driver.get_screenshot_as_base64(). These methods still represent the current window screenshot; changing the output form does not make it a full-document capture.

7. Troubleshooting

Symptom Likely cause Fix
Image is portrait-shaped Height was set larger than width, or sizing happened after capture Call set_window_size(width, height) with width greater than height before taking the screenshot.
Page still uses its mobile layout The effective rendering size is below the site’s responsive breakpoint, or the environment differs from the one used to choose dimensions Increase the width and inspect the page in the actual browser and driver environment. Selenium notes that screen resolution can affect rendering.
Screenshot is missing or cannot be opened The destination is unwritable, the path is wrong, or a non-PNG extension was used with the file method Use a writable path ending in .png; check the return value of get_screenshot_as_file and create parent directories if needed.
Capture shows a loading state or missing content The page had not reached the required state when the screenshot was taken Wait for a page-specific element or other condition before capture.
Only the visible region appears The ordinary screenshot captures the current window, not automatically the entire document Use a supported full-document method for your chosen browser. The documented Selenium Python full-document method cited here is Firefox-specific.
Expected a rotated landscape PNG after using PDF settings PDF print orientation controls printed PDF output Set the browser window dimensions for PNG capture; use PDF printing only when the desired output is a PDF.
Browser fails before the capture runs The browser/driver installation or configuration is incompatible or unavailable Confirm that the browser and WebDriver are installed and compatible with your Selenium setup, then retry in the same environment used for capture.

8. Performance, reliability, and cost

Local Selenium capture spends time starting or connecting to a browser, loading the page, waiting for the desired state, and writing the PNG. Reuse a browser session when capturing several pages in one controlled workflow, but always close it in a finally block or equivalent cleanup path. In CI or another remote environment, keep the browser version, driver setup, and requested dimensions consistent so layout changes are easier to diagnose.

Screenshot capture itself writes image data to disk or returns it in memory. Large dimensions and complex pages can produce larger images and more processing work. Choose a size that fits the task and avoid waiting for every network request if a specific page element is a better readiness signal. No universal performance figure applies across sites and environments.

Or skip the browser setup

If you need a landscape webpage capture without maintaining a Selenium browser, ScreenshotNeo provides a screenshot API and MCP server. Set the viewport to landscape dimensions in your request; see the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Use your target URL and API key in these examples. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot. Bot checks, blank pages, and failed loads are never billed, and response headers report the page verdict and billing status. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Create a free ScreenshotNeo account to get 1,000 screenshots a month with no card.

FAQ

Does Selenium have a special landscape screenshot command?

No. Set the browser window width larger than its height, then use the regular screenshot method.

Does set_window_size take height before width?

No. Its arguments are width, height.

Will the screenshot include the whole webpage?

The regular screenshot is for the current window. Full-document capture is a separate browser capability; the Selenium Python API cited here documents it for Firefox.

Can I capture landscape PDF with Selenium?

Yes, Selenium documents PDF printing with landscape orientation. That produces a PDF workflow and does not change PNG screenshot orientation.

Sources