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

First choose what the screenshot should contain: the visible browser viewport, just the header element, or the entire document. In Python, driver.save_screenshot("page.png") saves a PNG of the current window; do not assume that ordinary call captures the whole page. For a full-document capture in Chromium, Selenium’s versioned DevTools API documents Page.captureScreenshot with captureBeyondViewport, but compatibility depends on your installed Selenium and browser versions. Whichever route you use, check whether the fixed header appears once, is clipped, or overlays content.

Choose the screenshot scope first

“A screenshot of a webpage” can mean three different outputs, and the right Selenium method depends on which one you need.

What you need Approach Fixed-header consideration
Visible viewport Use the WebDriver window screenshot. Shows the header as it appears in the current viewport.
Header or another component only Locate the element and take an element screenshot. Captures the selected element, not the whole page.
Entire document Use a browser-specific full-page route, or scroll and stitch viewport captures. With scrolling and stitching, a fixed or sticky header can recur in segments or overlap content; verify the output.

Selenium’s WebDriver examples describe screenshots of the current context and individual elements. Its Python WebDriver API describes the driver screenshot as a PNG image of the current window.

Capture the visible viewport in Python

This is the simplest portable starting point when the desired result is what a user can see without scrolling. Replace the example URL with the target page. Add a wait appropriate to the page if its content loads asynchronously; a screenshot taken before the relevant content settles may not represent the final view.

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

 driver = webdriver.Chrome()
 try:
     driver.get("https://example.com")
     driver.save_screenshot("page.png")
 finally:
     driver.quit()

Remove the leading space before driver = if copying this snippet verbatim: Python code should be indented consistently as below.

from selenium import webdriver

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
    driver.save_screenshot("page.png")
finally:
    driver.quit()

The screenshot call targets the current window. The referenced API documentation does not establish that it always captures the complete document, so inspect the saved image dimensions and page coverage rather than labeling this a full-page capture by default.

Capture only the header element

If the deliverable is the header itself—for example, a logo or navigation component—take an element screenshot instead of capturing and cropping the page. The selector below is illustrative; use a selector that identifies the actual header on your page.

from selenium.webdriver.common.by import By

header = driver.find_element(By.CSS_SELECTOR, "header")
header.screenshot("header.png")

Selenium’s examples include element screenshot support. If the selector matches the wrong element or multiple candidate elements exist, refine it to target the intended header.

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

Capture beyond the viewport in Chromium

For a full-document screenshot, one documented Chromium-specific option is Selenium’s DevTools Page.captureScreenshot command with the captureBeyondViewport parameter. The linked Selenium DevTools Javadoc documents that parameter in the v124 binding for Selenium 4.22.0. That versioned reference is not a guarantee that the same API is available in every Selenium installation or browser version. Confirm compatibility with the versions you actually run before building a workflow around it.

Selenium’s JavaScript execution method can inspect or modify page state, but executing JavaScript by itself does not guarantee a consistent full-page screenshot. Use scripts only for a defined page-specific need, and validate any resulting visual changes.

Handle fixed and sticky headers deliberately

A header positioned with position: fixed or position: sticky may remain visible while the document scrolls. If a full-page workaround captures successive viewport images and stitches them together, the header may appear in more than one segment or overlap the content. This is a behavior to check on your page, not a universal Selenium defect.

  • If the header should appear once as part of the page, prefer a full-document capture method that produces that layout and verify the result.
  • If repeated headers are acceptable, a scroll-and-stitch workflow may suffice, but inspect segment boundaries and overlaps.
  • If the header should not appear, hiding it with page-specific CSS or JavaScript is an option only when changing the captured page is acceptable. Do not assume a generic mutation will preserve the layout.

Browser, viewport size, page scripts, lazy-loaded content, and nested scrolling can all affect the output. Selenium’s API references establish screenshot primitives, not a single tested procedure that resolves every header layout.

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

Verify the saved image

After capture, open the output and check the result rather than relying only on a successful method return.

  • Confirm the file exists, opens, and has the expected format and pixel dimensions.
  • Check that the intended content is present, including content below the initial viewport when full-page output was required.
  • Inspect the header: does it appear once, repeat at scroll boundaries, get clipped, or cover page content?
  • For pages with lazy-loaded sections, wait for or deliberately trigger the relevant content before capturing, then verify that it rendered.

Troubleshooting

The image contains only the first screen

save_screenshot is documented as a current-window screenshot. Use a compatible full-page method for your browser or a scroll-and-stitch workflow, then check the resulting dimensions and coverage.

The header appears more than once

This can occur in a segmented scroll-and-stitch capture because a fixed or sticky element stays in view at successive scroll positions. Inspect the segment boundaries. If the header should appear only once, choose a capture method that yields the desired layout or alter the header only when that change is acceptable.

The header is clipped or covers text

Check the captured viewport, scroll position, and page-specific header behavior. A fixed header can overlay content, and changing viewport size or scroll position may change what is visible. Validate the actual output instead of assuming the screenshot method will reposition the page.

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

The header selector fails

The example selector header is not guaranteed to match every site. Inspect the page’s markup and use a selector for the actual element before calling element.screenshot().

The full-page DevTools option is unavailable

The documented API reference is specifically for Selenium 4.22.0’s Chromium v124 DevTools binding. Check that your installed Selenium package exposes the relevant binding and that it matches your browser setup; otherwise use a compatible route or segmented capture.

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 without setting up Selenium and browser capture logic, ScreenshotNeo offers a website screenshot API and MCP server. A single request can return an image or PDF. Consent banners are accepted before capture, and more than 60 known consent platforms, newsletter popups, and chat widgets can be removed; each of those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, with response headers indicating the page verdict and billing status. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf.

For the API, create an access key and use the documented ScreenshotNeo API documentation. Example cURL request:

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000. Sign up for free ScreenshotNeo screenshots.

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.