First decide what you need to capture: the visible browser window, the header element alone, or the whole document. In Python, driver.save_screenshot("page.png") saves a PNG of the current window; do not assume that it captures the full document. For a full-page image in Chromium, Selenium’s DevTools route can request capture beyond the viewport, but the result and fixed-header behavior need checking in your browser and on your page.
Choose the screenshot scope
| What you need | Use | Fixed-header consideration |
|---|---|---|
| Visible viewport | WebDriver’s current-window screenshot | Captures the header as it is currently rendered in the window. |
| Header or another component only | The element’s screenshot method | Captures the selected element rather than the entire page. |
| Whole document | A browser-specific full-page route, such as Chromium DevTools | Check whether the header appears once, is clipped, or overlays content. |
Selenium’s standard screenshot APIs and examples cover the current context and individual elements. They do not establish that an ordinary WebDriver screenshot always includes the complete document. See Selenium’s WebDriver examples and the Python WebDriver API.
As an Amazon Associate I earn from qualifying purchases.
Capture the current viewport in Python
This example uses Python and Chrome through Selenium. It saves the visible window as a PNG, not a guaranteed full-document image. Replace the example URL with the page you need to capture.
Free tools Windows power users keep installed
One-click scans. No signup required.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
WebDriverWait(driver, 20).until(
lambda d: d.execute_script("return document.readyState") == "complete"
)
driver.save_screenshot("page.png")
finally:
driver.quit()
Remove the leading space before driver = webdriver.Chrome() if copying this into a Python file; the line should align with try:. Selenium’s Python API describes this call as saving a PNG image of the current window. Page load completion does not necessarily mean that every application-specific animation, asynchronous widget, or lazy image is ready, so add a wait for the content that matters on your page.
#1 Best Overall
Capture only the header element
If the deliverable is the header itself—not a full-page image—locate the actual header and call its screenshot method. The selector below is illustrative; inspect the target page and use a selector that identifies the intended element.
from selenium.webdriver.common.by import By
header = driver.find_element(By.CSS_SELECTOR, "header")
header.screenshot("header.png")
This is an element screenshot, not a capture of the page behind the header. Selenium documents element screenshot support in its WebDriver examples.
Rank #2
Request a full-page capture in Chromium
For Chromium, Selenium’s DevTools bindings expose the Chrome DevTools Protocol method Page.captureScreenshot, including the captureBeyondViewport parameter. This is a Chromium-specific route, not a portable WebDriver guarantee. The linked API reference is specifically for Selenium 4.22.0’s v124 DevTools binding; confirm that your installed Selenium version includes a compatible DevTools package for your browser.
The following Java example shows the shape of the call using that versioned binding. Keep Selenium’s DevTools artifacts aligned with your Selenium version and the Chromium major version. Depending on the generated binding and version, command signatures or package names may differ.
Rank #3
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.v124.page.Page;
ChromeDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
DevTools devTools = driver.getDevTools();
devTools.createSession();
String data = devTools.send(Page.captureScreenshot(
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(true),
Optional.empty()
));
Files.write(Path.of("page.png"), Base64.getDecoder().decode(data));
} finally {
driver.quit();
}
Imports and optional arguments shown here correspond to a versioned generated API and may need adjustment for the exact artifact in your project. Consult the Selenium 4.22.0 v124 DevTools reference for the documented captureBeyondViewport parameter and generated method signature. The method requests capture beyond the viewport; validate the output dimensions and layout rather than assuming every site’s sticky behavior will render as intended.
What happens to a fixed header in a full-page image?
A fixed or sticky header is positioned relative to the viewport or its scrolling container. The final image depends on how the capture is produced and on the page’s implementation. The official references cited here do not establish one universal outcome for fixed headers across browsers and pages.
- With a browser’s beyond-viewport capture, inspect whether the header appears once, overlays page content, or is clipped.
- If you scroll through the page and stitch separate viewport screenshots, the header may recur in multiple segments. Treat this as a risk to check, not as a guaranteed Selenium defect.
- If the desired image should omit the header, changing page styles may be an option, but only when altering the captured appearance is acceptable. A CSS change is page-specific and should be tested.
Selenium JavaScript execution can inspect or change page state, but executing JavaScript alone does not guarantee a consistent full-page screenshot. Selenium shows JavaScript execution examples in its WebDriver documentation.
Validate the screenshot before relying on it
- Confirm the expected PNG file exists and opens.
- Check its pixel width and height against the viewport or document dimensions you intended to capture.
- Look at the top, middle, and bottom of the image. Confirm that the header is present, not repeated unexpectedly, and not covering important content.
- Check pages with lazy-loaded images, nested scrolling regions, delayed content, or page scripts separately; these can affect what is rendered when the capture runs.
- Repeat the check after changing browser, Selenium, viewport, or page versions.
Troubleshooting
The screenshot stops at the viewport
Cause: The ordinary WebDriver screenshot is a current-window capture, and full-document behavior is not guaranteed by that API description. Fix: Use a compatible Chromium DevTools capture route when whole-document output is required, or deliberately scroll and stitch segments while checking for repeated fixed elements.
Rank #4
The fixed header appears more than once
Cause: A scroll-and-stitch workflow may include the viewport-fixed header in every segment. Fix: Use a full-page capture route that produces the desired layout, or hide the header only if that is acceptable for the output. Inspect the assembled image before using it.
The header is missing, clipped, or covers text
Cause: The header’s behavior and the capture method may interact differently on the target page. Fix: Check the exact capture route, viewport, page dimensions, and header selector; compare the output with the page at the same scroll position. There is no universal CSS adjustment established for every implementation.
Best Value
The image is blank or content is incomplete
Cause: The page may not have finished rendering relevant content when the screenshot ran. Fix: Wait for a page-specific element or state rather than relying only on navigation completion, and verify that the target content has loaded before capture.
Recommended Free Tools
The DevTools Java code does not compile
Cause: The example targets Selenium’s v124 DevTools binding documented for Selenium 4.22.0; generated bindings and package versions can vary. Fix: Align your DevTools artifact with your Selenium and Chromium versions and check the generated Page.captureScreenshot signature in the matching API documentation.
Or skip the browser setup
If you need a screenshot without managing Selenium and a browser session, ScreenshotNeo provides a URL-based screenshot API. One GET request returns an image or PDF; here is a cURL example saving a WebP image:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for request options. It accepts consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides screenshot tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Learn more at ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.
Frequently Asked Questions
Does Selenium’s JavaScript execution method take a full-page screenshot?
No. It can inspect or alter page state, but it does not itself guarantee a consistent full-page capture.
Can Selenium take a screenshot of just a header?
Yes. Locate the header element with an appropriate selector and use that element’s screenshot method.
Quick Recap
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.




