Use one Selenium WebDriver session to sign in, open the protected page, verify that its content loaded, and then call driver.save_screenshot("page.png"). The method captures the current browser window to a PNG; it does not prove that the page is authenticated, so wait for an application-specific marker before saving.
Capture a protected page in the same Selenium session
Here is an illustrative Python pattern. Replace the example URLs and CSS selector with values from your application. The login step is intentionally left to the permitted flow for your site or test environment.
As an Amazon Associate I earn from qualifying purchases.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
try:
driver.get("https://example.test/login")
# Complete the site's permitted login flow here, or establish test state
# through an approved application API before navigating to the target page.
driver.get("https://example.test/account/report")
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-testid='report']"))
)
saved = driver.save_screenshot("page.png")
if not saved:
raise OSError("Selenium could not save page.png")
finally:
driver.quit()
When copying, remove the single leading space before driver = webdriver.Chrome(); it is not valid at that indentation level. This is a pattern, not a tested script or guarantee of compatibility with a particular application. Ensure the target page navigation occurs after authentication in the same browser session.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Choose how to establish the signed-in state
Use the site’s permitted interactive login for a one-off capture
For a single screenshot, completing the site’s supported login flow in the WebDriver-controlled browser may be the simplest approach. If login requires MFA, SSO, a CAPTCHA, or other checks, follow the site’s rules and your test environment’s approved process; Selenium behavior for those application-specific controls is not universal.
#1 Best Overall
Use an approved API or test setup for repeatable runs
For recurring automated tests, an application-provided API or other approved setup can establish test state without repeating a browser login. Selenium’s test-practice guidance says, “Eliminating logging in via web browser before every test will improve both the speed and stability of the test,” and recommends approaches such as using an API to log in and set a cookie: Selenium: Generating application state. This is guidance, not a measured performance guarantee.
Add a cookie only after opening its domain
WebDriver must first be on a page within the cookie’s domain before adding that cookie. A small page on the same site can be useful if its homepage is slow or large. The cookie must also match the domain and session requirements of the application; a cookie alone may not create all required application state. See Selenium’s cookie documentation for the domain constraint.
Rank #2
Verify the protected page before saving
A successful navigation call does not establish that Selenium reached the intended authenticated content. The application may have redirected to login, shown an access-denied page, or failed to render the expected data. Wait for a visible marker that belongs to the protected page, such as a report container or signed-in account element, as in the example’s data-testid selector. Choose a marker specific enough that it would not also appear on the login screen.
The selector is application-specific; Selenium does not define a universal login-success element. If the wait times out, inspect the current URL and page state before saving rather than treating any screenshot as a successful capture. Selenium’s API captures the current browsing context, so taking the image without this check can produce a valid PNG of the wrong page: Python WebDriver API.
Rank #3
Know what the screenshot includes
Current window or viewport
save_screenshot() saves the current window to a PNG file. Selenium’s general WebDriver screenshot methods should not be treated as guaranteed full-document capture. Official examples take screenshots after navigating to a page; the API also provides screenshot data as bytes or Base64 if you need to process or embed the image instead of writing it directly to disk. See the Python WebDriver API and Selenium’s windows and tabs examples.
Full-document capture
If you need the entire document rather than the current view, use a documented full-page method supported by your exact browser and driver binding. Selenium’s Firefox Python API documents full-document screenshot methods such as save_full_page_screenshot(...); do not assume the same method or behavior is available in every browser: Firefox Python WebDriver API.
Handle common failures
| Symptom | Likely cause | What to do |
|---|---|---|
| The image shows the login page | Authentication did not complete, the session expired, or the protected URL redirected. | Check the current URL and login result, then wait for a protected-page marker before saving. |
| The expected-element wait times out | The selector is wrong, the page is still loading, access was denied, or the target content did not appear. | Inspect the page and selector, and verify the account has permission to view the target. |
| A cookie cannot be added | The browser is not currently on a page in the cookie’s domain, or the cookie does not meet domain requirements. | Navigate to a page on the correct domain first, then add a cookie compatible with the application’s session. |
| The output file is missing or not saved | The destination path is unwritable or an I/O error occurred. | Use a known writable path and check the Boolean return value from save_screenshot(); Selenium documents False for an I/O failure. |
| The screenshot cuts off lower content | The method captured the current window rather than the full document. | Use a full-page method documented for the browser and binding you run, or capture the needed sections separately. |
Or skip the browser setup
For public pages, ScreenshotNeo can capture a URL with one GET request. It does not replace Selenium for a protected page that requires an authenticated browser session: the example below requests a URL and does not include a login session.
See the ScreenshotNeo API documentation for request options.
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
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.
Recommended Free Tools

