Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk8 min

Capture a Logged-In Website Screenshot with Selenium When Login Uses SSO

A practical Selenium guide to capturing an SSO-protected page: complete sign-in in the browser, validate the app state, handle new windows, and save the right screenshot.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture an authenticated page, run Selenium through the site’s normal sign-in flow in the same browser session, wait for a reliable marker that proves the app is logged in and the target content is rendered, then save a screenshot. If SSO opens another tab or window, switch to the handle containing the application before checking the marker or capturing.

The exact redirects and authentication prompts depend on the site and its identity-provider configuration. Use an authorized test account and the organization’s approved test path; Selenium should not be used to bypass MFA or other access controls.

As an Amazon Associate I earn from qualifying purchases.

Why SSO changes the screenshot workflow

SSO is a browser-mediated flow in many deployments: the browser may leave the application for an identity provider, complete authentication there, and return to the application. OAuth 2.0 describes an authorization-code flow in which the user authenticates at the authorization server through the user-agent before a code returns to the client; OpenID Connect adds identity and authentication semantics over OAuth 2.0. Neither label determines a particular website’s screens or redirects, which depend on its configuration. See the OAuth 2.0 specification and OpenID Connect Core 1.0.

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

Selenium drives the browser in its current context, so successful sign-in alone is not enough: the script must be on the application page and wait until the content intended for the image is actually present. Selenium’s documentation describes WebDriver as driving a browser natively, as a user would, locally or through Selenium Server. See Selenium WebDriver.

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Capture the page with Selenium in Python

This example uses a local Chrome WebDriver, navigates to the application’s ordinary sign-in URL, waits for you to complete any approved interactive SSO prompts, and then waits for a site-specific authenticated element before saving the viewport. Replace the example URLs and CSS selectors with values for your application. The selectors must identify meaningful elements on the real sign-in and target pages; they are not universal SSO selectors.

  1. Install Selenium: python -m pip install selenium. Use a compatible browser and driver setup for your environment; Selenium’s browser options and driver configuration are described in Browser Options.
  2. Set the application URLs and selectors: choose the normal sign-in entry point, a stable marker visible only after authentication, and an element that represents the content to capture.
  3. Run the script: complete the approved SSO flow in the opened browser if it requires interaction. The script continues only after the target element appears.
  4. Check the output: the PNG is saved in the current working directory as logged-in-page.png.
from pathlib import Path

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

LOGIN_URL = "https://app.example.com/sign-in"
# Replace this with an element that appears only in the authenticated app.
AUTHENTICATED_MARKER = (By.CSS_SELECTOR, "[data-testid='account-menu']")
# Replace this with the page element whose presence means the image is ready.
TARGET_CONTENT = (By.CSS_SELECTOR, "main h1")

options = webdriver.ChromeOptions()
# Keep the browser visible when a person must complete an approved SSO or MFA prompt.
# For an approved unattended test setup, configure headless mode if appropriate:
# options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
wait = WebDriverWait(driver, 120)

try:
    driver.get(LOGIN_URL)

    # If the SSO flow needs a person, complete it in this browser window.
    # This wait is for the application's authenticated state, not a fixed sleep.
    wait.until(EC.presence_of_element_located(AUTHENTICATED_MARKER))

    # Wait separately for content that may render after authentication.
    target = wait.until(EC.visibility_of_element_located(TARGET_CONTENT))

    output = Path("logged-in-page.png")
    if not driver.save_screenshot(str(output)):
        raise RuntimeError(f"WebDriver did not save the screenshot to {output}")
    print(f"Saved viewport screenshot: {output.resolve()}")
finally:
    driver.quit()

The 120-second wait is a configurable timeout, not a guarantee that every SSO flow finishes within that period. Increase it only when the approved flow reasonably needs longer; do not replace state checks with a guessed delay. Selenium notes that navigation can complete at a document readiness state while JavaScript-driven content continues loading. Use explicit waits for the marker and content you need. Avoid mixing implicit and explicit waits because their interaction can make timing unpredictable; see Selenium waiting strategies.

Use a marker that proves the right state

A useful authenticated marker is an account menu, signed-in navigation item, or another application-specific element that is not present on the public or sign-in page. Then wait for a target-page element or other stable content that must appear in the screenshot. A URL change can help diagnose the flow, but it is weaker evidence than a page-specific element: redirect URLs can vary, and a page can reach its destination before its dynamic content is ready.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

Handle SSO that opens a new tab or window

When a provider or application opens another browsing context, Selenium does not automatically make the intended page current. Record handles around the action that begins the flow, inspect the available contexts, and switch to the one whose URL and page-specific element identify the target application. Do not rely on handle ordering alone. Selenium’s windows and tabs documentation explains how to work with these contexts.

# Capture the handles before the action that may open a context.
handles_before = set(driver.window_handles)

# Perform the relevant click or continue the SSO flow here.
# For example: driver.find_element(By.CSS_SELECTOR, "button.sso").click()

wait.until(lambda d: len(set(d.window_handles) - handles_before) > 0)
new_handles = set(driver.window_handles) - handles_before

# A new handle is only a candidate. Validate the destination and marker.
for handle in new_handles:
    driver.switch_to.window(handle)
    try:
        wait.until(EC.presence_of_element_located(AUTHENTICATED_MARKER))
        wait.until(EC.visibility_of_element_located(TARGET_CONTENT))
        break
    except TimeoutException:
        continue
else:
    raise TimeoutException("No newly opened window contained the authenticated target page")

# Capture in the validated current window.
driver.save_screenshot("logged-in-page.png")

Some flows open a provider tab and later return to the original application tab rather than finishing in the new tab. In that case, examine both the original and new handles and switch to whichever one contains the authenticated application and target element. The reliable criterion is the page state, not whether a handle was newly created.

Choose a viewport or element screenshot

driver.save_screenshot(...) captures the current browser window’s visible viewport. This is appropriate when the frame of the page matters or when you want a conventional browser-window image. For a focused crop, wait for the element and use its screenshot method instead:

Rank #3
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
target = wait.until(EC.visibility_of_element_located(TARGET_CONTENT))
target.screenshot("target-element.png")

An element screenshot is limited to that element rather than the complete page. Selenium’s official examples cover current-window and element screenshots, including Python’s driver.save_screenshot('./image.png'); see WebDriver documentation.

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

SSO, MFA, and session handling

Authentication requirements are controlled by the site and organization. Use an authorized test identity, documented test identity-provider settings, or an approved interactive checkpoint if policy requires a person to complete MFA or conditional access. OWASP’s Authentication Cheat Sheet provides general authentication guidance; it does not make any particular automation path appropriate for your organization.

Do not treat cookie injection or copied session tokens as a generic workaround. Selenium cookie operations are constrained by browser context and domain, while SSO state can involve the provider, application, server-side state, and policy checks. Use the normal authorized flow. Selenium’s cookie documentation describes cookie operations.

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Close the WebDriver session in a finally block, as in the example, and protect screenshots and any persistent browser profiles as potentially sensitive data. Avoid leaving authenticated sessions or images in shared locations.

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

Troubleshoot blank, pre-login, or incomplete screenshots

Symptom Likely cause What to check or change
Image shows the sign-in page or identity provider The callback has not finished, or Selenium is still in the provider context. Inspect driver.current_url and the current handle; switch to the application context and wait for its authenticated marker.
SSO opened an unexpected tab The flow created another context, or returned to the original one. Compare window handles before and after the flow, inspect candidate URLs, and validate each candidate with an application-specific element. Do not assume the last handle is correct.
Page loaded but the image misses content Document readiness occurred before client-side rendering or data loading completed. Wait for the actual target element to become visible, or for another stable condition tied to the content being captured. Avoid relying only on a fixed sleep.
Explicit waits time out The selector may be wrong, the user is not authenticated, the intended tab was not selected, or the page has not reached the expected state. Inspect the current URL and visible page, verify selectors against the application, and confirm the authorized SSO flow completed. Increase the timeout only if the flow legitimately needs more time.
Cookie-based shortcut does not authenticate The session depends on more than one cookie or on server state, domain context, or identity-provider policy. Return to the approved browser-mediated sign-in flow rather than copying tokens or injecting cookies as a general bypass.
MFA or conditional-access prompt blocks unattended capture The organization requires an authentication checkpoint. Ask the site or identity administrator for an approved test identity or documented test configuration, or use an authorized interactive checkpoint. Do not attempt to defeat the control.

Or skip the browser setup

If you only need a website screenshot and do not need your own authenticated Selenium session, ScreenshotNeo provides a screenshot API and MCP server. It cannot sign in to a private SSO-protected application on your behalf; use Selenium for that authorized, browser-based flow. For pages it can access, one GET request returns an image or PDF. The API parameter names other screenshot APIs use also work, which can make switching easier. See the ScreenshotNeo API documentation.

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://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Best Value
FIDO2 U2F Security Key Passkey Two-Factor Authentication (2FA) USB Key PIN+Touch (Non-Biometric) USB-A Type TrustKey T110
  • Security Key : Protect your online accounts against unauthorized access by using FIDO2 and U2F authentication with T110. It's the world's most protective security key that works with windows, Mac OS, Linux as well as Chrome, Firefox, Edge and many other major browsers.
  • Certified with the new FIDO2 standard, T110 provides the benefit of fast login and strong protection against phishing, account takeover as well as many other online attactks.
  • Works with : Bank of America, Github, Google, Microsoft, DUO, Twitter, Facebook, Dropbox, Apple, ebay, BINANCE, mor and more.
  • Fits USB-A port : Insert the T110 security key into the USB-A port of each service and log in conveniently with one touch
  • For the driver download and user guide, please visit TrustKey Solutions Home support page.

Frequently Asked Questions

Does Selenium bypass SSO or MFA?

No. Selenium automates the browser flow you are authorized to use; authentication policy and MFA must be handled through an approved identity-provider or interactive test path.

Can I take a screenshot of an SSO-protected page with ScreenshotNeo instead?

Not as a substitute for signing in through your organization’s SSO. Use Selenium in the authorized browser session for a private page; ScreenshotNeo is for pages its capture service can access.

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

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 *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.