Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Take a Screenshot of a Password-Protected Web App with Selenium

A practical Selenium workflow for authenticated screenshots: choose UI login or supported session setup, wait for the protected page, then save and validate the PNG.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To screenshot a password-protected page with Selenium, first establish an authorized authenticated session—by logging in through the UI or by using an application-supported API/session setup—then wait for a reliable marker on the protected page and save the image. A successful navigation alone does not prove that the app has finished rendering the content you need.

Choose how to authenticate

Use a dedicated test account and an application-approved route. The right setup depends on what the test is meant to cover:

As an Amazon Associate I earn from qualifying purchases.

Approach Use it when Trade-off
Log in through the UI The login flow itself is under test, or there is no supported setup API. Exercises the real form and redirects, but repeats browser work and depends on stable login selectors.
Establish state through an API or cookie The test concerns the protected page, and the app provides an authorized way to create a test session. Can reduce repetitive setup, but depends on the app’s session rules, cookie scope and identity-provider configuration.

Selenium’s guidance on generating application state says, “Selenium should not be used to prepare a test case.” In practice, that favors supported external setup for repetitive preparation; keep UI login when validating login behavior.

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

Log in through the UI in Python

Install Selenium in the test environment and configure a compatible browser and driver. Replace the example URL and selectors with those used by your app. Keep credentials in environment variables or a secrets manager in real test code rather than hard-coding them.

#1 Best Overall
from pathlib import Path

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

# Supply these from the test environment; do not hard-code real credentials.
username = "test-user"
password = "test-password"

out = Path("artifacts")
out.mkdir(parents=True, exist_ok=True)

driver = webdriver.Chrome()
try:
    driver.get("https://app.example.test/login")
    wait = WebDriverWait(driver, 15)

    wait.until(EC.visibility_of_element_located((By.NAME, "username"))).send_keys(username)
    driver.find_element(By.NAME, "password").send_keys(password)
    driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()

    # Replace this with a stable marker visible only after login.
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-testid='account-home']")))

    saved = driver.save_screenshot(str(out / "protected-page.png"))
    if not saved:
        raise OSError("WebDriver could not save the screenshot")
finally:
    driver.quit()

The 15-second wait is an example timeout, not a guarantee that every app will be ready within that interval. Choose a timeout suitable for your test environment and fail clearly if the authenticated marker never appears.

Set up a session with an application-approved cookie

If the app supports an authorized test API that returns a session cookie, navigate the WebDriver session to the cookie’s domain before adding it. Selenium’s cookie documentation requires the current browser domain to match the cookie’s domain.

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

session_cookie_value = obtain_test_session_cookie()  # Use your app's supported test setup.
driver = webdriver.Chrome()
try:
    driver.get("https://app.example.test/")  # Establish the target domain first.
    driver.add_cookie({"name": "session", "value": session_cookie_value})
    driver.get("https://app.example.test/protected")

    wait = WebDriverWait(driver, 15)
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-testid='account-home']")))
    driver.save_screenshot("protected-page.png")
finally:
    driver.quit()

obtain_test_session_cookie() is intentionally app-specific: the app determines how the session is created and which cookie fields and attributes it needs. Do not assume cookie injection will bypass SSO, MFA or identity-provider policies. Validate the supported setup with your app.

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

Wait for the content, not just the page load

After either authentication route, wait for a condition that proves the content to capture is present—for example, a visible dashboard container, account heading or stable test ID. Selenium’s waiting strategies describe explicit waits that poll until a chosen condition succeeds or the timeout expires. They also warn: “Do not mix implicit and explicit waits.”

A fixed sleep may be too short on a slow run and waste time on a fast one. Prefer a meaningful condition, and make sure it represents the finished content rather than an element that appears while the page is still loading.

Document readiness and app readiness are different. Selenium’s browser options describe page-load strategies: normal waits for the document’s complete state, eager for interactive, and none does not block for readiness. JavaScript can still update the page after navigation returns, so pair any chosen strategy with an explicit wait for the content you need.

Rank #4
Sale
Diccik 1080P Webcam with Microphone, Full HD Web Camera for Desktop Computer and Laptop USB Computer Camera for PC Pro Streaming Webcam for Zoom/Skype/Teams, Plug and Play PC for Windows &Mac
  • Vivid Full HD 1080P Video Quality: Experience crisp, professional video with the DICCIK 1080p webcam. Delivering 1920 x 1080 resolution at a fluid 30fps, this web camera ensures clear images for every online calling session. Whether you are streaming or recording, it is a reliable computer camera that outperforms standard laptop cameras.
  • Integrated Microphone for Clear Audio: This pc webcam features a built-in noise-reducing mic. Designed as a computer camera with microphone for desktop, it captures your voice naturally while filtering background noise. Perfect for busy home offices, ensuring you are heard loud and clear on Zoom, Skype, and FaceTime.
  • Instant Plug and Play USB Connection: No software or drivers required. Our usb webcam is a true plug and play solution for your PC or Mac. Simply connect the camera for pc to your USB port, and it’s ready in seconds. The flexible clip makes it an easy-to-install monitor camera or desktop camera.
  • Automatic Light Correction for Dim Lighting:Look your best even in low-light environments. This computer camera for desktop automatically adjusts brightness and white balance to match your room's light. From bright offices to dim bedrooms, this streaming webcam ensures a professional look without extra ring lights.
  • Wide Compatibility for Work and Play:A versatile pc camera webcam that works seamlessly with Windows 7/10/11, macOS, and Linux. This webcam for mac and webcam for laptop is fully optimized for Microsoft Teams, Google Meet, and YouTube. An essential camera for computer users across all major operating systems.

Save and validate the screenshot

In Python, save_screenshot(path) writes a PNG and returns a boolean. Check that result, as in the UI-login example, and ensure the destination directory exists. Capture only after the authenticated marker is ready; otherwise the output may show a login page, loading state or incomplete app.

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

Selenium’s API documentation describes screenshot capture as best effort. The captured area can depend on the driver and browser context, so do not assume that a normal screenshot is always a full-page capture. If the test requires a full-page image, verify the behavior for the browser and driver you use.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

  • The screenshot shows the login page: The login may have failed, the session may not have persisted, or the cookie may be invalid or out of scope. Check the browser’s resulting URL and wait for an authenticated-only marker before saving.
  • The screenshot is blank or incomplete: Navigation may have returned before client-side rendering finished. Wait for a visible, stable element that represents the content to capture rather than relying on navigation or a fixed delay alone.
  • add_cookie fails or has no effect: First navigate to the cookie’s target domain. Confirm the cookie name, value, scope and attributes match the application’s supported test-session setup.
  • The explicit wait times out: Check whether login succeeded, whether the selector exists in the current page, and whether the element is visible. Use a stable test ID or other app-owned marker where possible; increase the timeout only if the app legitimately needs more time.
  • The saved file is missing: Confirm the output directory exists, the process can write there, and save_screenshot returned true. Keep the exception visible so an unsuccessful capture fails the test instead of passing silently.
  • Timing is unpredictable: Avoid mixing implicit and explicit waits. Use explicit waits for the states relevant to this capture.

Or skip the browser setup

If you only need a screenshot and do not need Selenium to exercise the authenticated browser session, ScreenshotNeo offers a one-request screenshot API. Use the API key and target URL as shown; see the ScreenshotNeo 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

ScreenshotNeo does not replace an app-specific authenticated Selenium test: this example does not supply a login session for a password-protected app. For pages the service can capture, it accepts cookie/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, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing status. It also provides an MCP server with screenshot, page-info and PDF tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try it with no card.

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

Frequently Asked Questions

Can Selenium take a screenshot while a user is logged in?

Yes. Capture in the same WebDriver session after the app’s authenticated content is ready.

Does Selenium’s screenshot API guarantee a full-page image?

No. Screenshot capture is best effort, and the captured area depends on the browser and driver context; verify full-page behavior in your setup.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.