To screenshot a page that requires login, open it in a supported browser through Selenium, establish an authorized session in that browser, wait for the authenticated content you need, and save the browser window with driver.save_screenshot("page.png"). PhantomJS is a legacy option: Selenium’s changelog deprecated it and recommended headless Chrome or Firefox. For new or maintained scripts, use a current Selenium setup with a supported browser instead.
What “session-managed” means for a screenshot
A login-protected page is rendered in the context of a browser session. The screenshot must come from a browser that has completed the site’s authorized login flow or has been given valid session data in a way the site permits. Opening the target URL in a fresh browser is not enough: it may show a sign-in form, an access-denied page, or an intermediate challenge rather than the content you intended to capture.
This guide uses Selenium’s Python WebDriver API for browser control. Selenium documents saving the current window as a PNG with save_screenshot, as well as retrieving and adding cookies in the current WebDriver session. Those API capabilities do not mean that a cookie copied from another browser will recreate every site’s login. Authentication can depend on other state or checks, and the exact behavior must be confirmed for the site you are authorized to access.
Choose the browser: use PhantomJS only for legacy work
Selenium’s Python changelog for version 3.8.1 says, “PhantomJS is now deprecated, please use either Chrome or Firefox in headless mode.” That makes PhantomJS relevant mainly when maintaining an older script or reproducing an old environment. The current Selenium Python API documentation is identified as version 4.49.0 and documents screenshot and cookie methods; it does not make PhantomJS a current browser recommendation. See the Selenium changelog and Python WebDriver API.
Recommended Free Tools
#1 Best Overall
For a new script, choose Chrome or Firefox in headless mode and verify that your installed Selenium, browser, and driver versions work together. The sources establish the general recommendation, not a version-by-version deployment matrix. Also check that your target site works in the selected browser; compatibility is target-specific.
Capture a logged-in page with Selenium Python
The following example illustrates the safe, general sequence: start a browser, complete an authorized login, wait for an element that proves the desired page has loaded, set the viewport, save the screenshot, and close the browser. The login form selectors and the authenticated-content selector are deliberately site-specific placeholders: replace them with selectors for a site you are permitted to use. The sample uses Chrome’s headless mode; consult the Selenium and browser documentation for setup appropriate to your installed versions.
Runnable workflow once you supply the site’s selectors
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
LOGIN_URL = "https://example.com/login"
TARGET_URL = "https://example.com/account/reports"
OUTPUT = Path("page.png")
options = webdriver.ChromeOptions()
options.add_argument("--headless")
# Set a consistent viewport for repeatable viewport screenshots.
options.add_argument("--window-size=1440,1000")
driver = webdriver.Chrome(options=options)
try:
wait = WebDriverWait(driver, 30)
driver.get(LOGIN_URL)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[name='username']"))).send_keys("YOUR_USERNAME")
driver.find_element(By.CSS_SELECTOR, "input[name='password']").send_keys("YOUR_PASSWORD")
driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()
# Wait for a page-specific sign that login succeeded.
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-test='account-home']")))
driver.get(TARGET_URL)
# Wait for the content to capture, not merely for navigation to begin.
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "main .report-title")))
if not driver.save_screenshot(str(OUTPUT)):
raise RuntimeError(f"Selenium did not save the screenshot to {OUTPUT}")
finally:
driver.quit()
print(f"Saved {OUTPUT.resolve()}")
Install Selenium in the Python environment you will use to run the script with python -m pip install selenium. Browser and driver setup depends on the versions installed on your machine; confirm the Selenium installation and the browser/driver arrangement before running the example. Do not commit real passwords to source control. For production use, supply credentials through an appropriate secret store or environment variables and follow the target site’s access rules.
Why the waits and checks matter
A fixed delay such as time.sleep(5) is not proof that login succeeded or the page is ready. Network speed, redirects, asynchronous rendering, and site behavior can change how long a page takes. A wait for a specific authenticated element makes the success condition explicit; choose an element that appears only when the relevant content is present. A timeout should be treated as a failed capture, not a cue to save whatever happens to be on screen.
Rank #2
The script checks the boolean returned by save_screenshot, which Selenium documents as indicating whether the PNG was saved successfully. Use a writable path, create any needed parent directory, and handle a false return or file-system error rather than silently reporting success. The Selenium API’s screenshot operation captures the current window; do not assume it captures the entire document. Full-page capture depends on browser-specific capabilities and page dimensions.
Restore cookies only when the target site’s session design permits it
Selenium’s WebDriver API can retrieve cookies visible to the current driver and add a cookie to the current browser session. Cookie attributes may include domain, path, expiry, secure, HTTP-only, and same-site scope. A cookie must be applicable to the page’s domain and path, and an expired or invalid session cookie will not authenticate the request. More importantly, some sites depend on additional cookies, local or session storage, CSRF state, device checks, or server-side expiry. A cookie by itself is not a universal login transfer mechanism.
If the site’s rules and implementation permit restoring a valid cookie, navigate to the relevant domain before adding a cookie, then reload or open the protected page and verify the authenticated content. Avoid copying session credentials into logs, public code, or screenshots; treat them as secrets. When uncertain, complete the site’s normal login flow within the Selenium browser.
Cookie operations in the current driver
# After navigating to the cookie's domain, and only with authorized session data:
driver.get("https://example.com/")
driver.add_cookie({
"name": "session_cookie_name",
"value": "VALID_SESSION_VALUE",
"path": "/",
# Include domain or other attributes only as appropriate for this site.
})
driver.get("https://example.com/account/reports")
# Inspect cookies available to this WebDriver session:
for cookie in driver.get_cookies():
print(cookie["name"], cookie.get("domain"), cookie.get("path"))
Do not print cookie values in routine diagnostics. The snippet is an API illustration, not a recipe for bypassing access controls or transplanting a session that the site has not authorized you to use. See Selenium’s cookie and WebDriver API documentation for current method details.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
What changes if you must keep an old PhantomJS script?
PhantomJS’s own legacy documentation describes a cookie jar that can be populated from a configured cookie file and used when opening relevant pages. This is historical PhantomJS behavior, not guidance for current Selenium projects. The old Selenium Python documentation also described PhantomJS/Ghostdriver integration. Before preserving that setup, check the versions and dependencies in the actual legacy environment; do not assume instructions for an old integration apply to current Selenium or browser releases.
If you need to reproduce an old result, keep the environment isolated, use only session data you are permitted to handle, and compare the captured page against a known expected state. For ongoing maintenance, plan to move the capture flow to headless Chrome or Firefox and revalidate login, readiness, and screenshot extent there. Selenium’s changelog is the source for the deprecation recommendation; PhantomJS’s API documentation describes its older cookie behavior, and legacy Selenium Python documentation covers its historical integration.
Viewport versus full-page screenshots
save_screenshot saves the current browser window to PNG. If the page is taller than the viewport, that method alone should not be treated as a guarantee that every part of the document appears in the image. Decide whether your deliverable is a viewport image or a full-page capture before choosing browser-specific techniques. If the task requires the complete document, verify the approach against your chosen browser, Selenium version, page dimensions, and target site rather than assuming a generic WebDriver method will scroll and stitch the page.
Set a deliberate viewport when screenshots need to be comparable. A headless browser’s window size affects what is visible, responsive layout, and the resulting image dimensions. Keep the target URL, viewport, browser version, and readiness condition consistent when repeatability matters; those choices are part of the capture setup, not incidental details.
Or skip the browser setup
If you want a screenshot API rather than managing a Selenium browser, ScreenshotNeo takes a URL in one GET request and returns a screenshot or PDF. For a public URL, the basic cURL request is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for authentication and options. For a page that requires login, the API’s custom cookies, headers, and Authorization options may be relevant, but whether they are sufficient depends on the target site’s authentication design; use only credentials and access methods you are authorized to use.
- Cookie banners are accepted and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before capture; each of these steps can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status.
- An MCP server offers
take_screenshot,get_page_info, andcapture_pdftools for Claude, Cursor, and other MCP clients. - The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month without a credit card.
Troubleshooting Selenium login screenshots
The screenshot shows the login page
- Likely cause: Login did not complete, the site redirected back to sign-in, or the session was not valid for the target route.
- Fix: Wait for a site-specific authenticated element after submitting the form, then verify the target page’s protected content before saving. If restoring cookies, check domain/path applicability and expiry, and use the site’s normal login flow if cookie restoration is unsupported.
The screenshot is blank or missing content
- Likely cause: The capture happened before the relevant content rendered, or the chosen selector does not represent readiness for this page.
- Fix: Wait for the actual content element and investigate whether the page is still loading or showing an intermediate state. A fixed sleep alone does not establish readiness.
The script times out waiting for an element
- Likely cause: The selector does not match the current page, the page has not reached the expected state, or the login failed.
- Fix: Check the selector against the rendered page and make the wait condition match the element that proves the required state. Distinguish a login-success element from the target-page content element.
The cookie is rejected or does not log in
- Likely cause: The cookie is expired, scoped to a different domain or path, or the site requires additional session state or checks.
- Fix: Use a currently valid cookie only where permitted, add it after navigating to the applicable domain, and verify the resulting page. Prefer the authorized interactive login flow if the site’s session cannot be restored from a cookie alone.
The PNG is not where expected
- Likely cause: The process’s working directory differs from the one you expected, the destination is not writable, or saving failed.
- Fix: Use an explicit path, check
save_screenshot‘s return value, and confirm the resolved path and parent-directory permissions.
The image cuts off the page
- Likely cause: Selenium’s generic screenshot method captures the current window rather than promising full-document capture.
- Fix: Set a sufficiently large viewport for a viewport-oriented image, or select and verify a browser-specific full-page method for your actual browser and page.
Operational considerations
For reliability, make the capture fail visibly when login, the expected content, or the screenshot write fails. Close the WebDriver in a finally block so the browser process is released even after an exception. If you need to diagnose a failure, record non-sensitive details such as the step that timed out and the URL path; do not expose passwords, cookie values, or authorization headers in logs.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
For performance, avoid arbitrary long sleeps when a specific readiness condition can be awaited. A browser still has to start, authenticate, navigate, render, and write the image, so keep the automation focused on the required page and state. No universal timing or cost figure applies: those depend on the target site, browser environment, and implementation. For repeated or large-scale capture, separately validate browser capacity, rate limits, and the site’s access policy rather than assuming one successful manual run establishes safe production behavior.
Frequently Asked Questions
Does Selenium’s `save_screenshot` save a JPEG?
The documented `save_screenshot(filename)` method saves the current window as a PNG.
Can I use PhantomJS for a new Selenium project?
It is a legacy choice; Selenium’s Python changelog deprecated PhantomJS and recommended headless Chrome or Firefox.
Does adding one cookie always restore a login?
No. The site may require other state or checks, and the cookie must be valid and correctly scoped.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →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.

