Authenticate the browser first, wait until the protected page is ready, then save a screenshot. In Python, Selenium’s driver.save_screenshot("screenshot.png") saves the current window as a PNG and returns whether the save succeeded. HTTP Basic Authentication is different from filling in a website’s HTML login form; the method below is for Basic Auth, and URL-based credentials do not work in every browser or remote Selenium service.
Set up Selenium and identify the protected page
Install Selenium and make sure the browser you intend to use is available in your environment. The example uses Python with Chrome. Replace the example URL and the readiness selector with values for your own site.
python -m pip install selenium
Pass a complete URL to driver.get(), including https:// or http://. Before automating the capture, identify an element that appears only when the authenticated page has loaded, such as a main content container or a page heading.
Authenticate with URL credentials when your browser supports it
One conditional approach is to put the username and password before the hostname: https://username:password@example.test/protected. BrowserStack documents this pattern for initial navigation, but warns that support varies: some browser versions no longer support it, and the documented URL method does not apply to some Safari on macOS and Android combinations. Verify it with your browser and execution provider before relying on it. Characters such as @ and : in credentials may need URL encoding.
Recommended Free Tools
#1 Best Overall
Because the credentials are part of the navigation URL, avoid printing that URL, exposing it in shared logs, or committing real credentials to source control. Use a test account and keep its credentials outside the code. The sample reads them from environment variables and quotes them for use as URL components.
Python example: navigate, wait, and save
import os
from urllib.parse import quote, urlsplit, urlunsplit
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
username = os.environ["BASIC_AUTH_USERNAME"]
password = os.environ["BASIC_AUTH_PASSWORD"]
protected_url = "https://example.test/protected"
parts = urlsplit(protected_url)
if parts.scheme not in ("http", "https") or not parts.hostname:
raise ValueError("protected_url must be a complete HTTP or HTTPS URL")
# URL credentials are not supported in every browser/provider.
user_info = f"{quote(username, safe='')}:{quote(password, safe='')}@"
authenticated_url = urlunsplit(
(parts.scheme, user_info + parts.netloc, parts.path, parts.query, parts.fragment)
)
driver = webdriver.Chrome()
try:
driver.get(authenticated_url)
# Replace this selector with an element that confirms your protected page is ready.
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
)
if not driver.save_screenshot("screenshot.png"):
raise RuntimeError("Selenium could not save screenshot.png")
finally:
driver.quit()
Set BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD in the process environment before running the script. The main selector and 10-second wait are examples, not universal readiness guarantees; use a meaningful element and timeout for your application. If the page redirects, renders an authentication error, or does not expose the expected element, do not capture it as though authentication succeeded.
Rank #2
Use a provider-specific method when URL credentials do not work
Authentication support can depend on whether Selenium runs locally or through a hosted browser provider, as well as on browser and platform. BrowserStack documents a JavaScript executor named sendBasicAuth for its own service to handle authentication during later navigation. It is BrowserStack-specific, not a generic Selenium WebDriver command; do not copy it into a local Selenium script and expect it to work. See BrowserStack’s Basic HTTP Authentication documentation for its supported route and limitations.
If URL credentials are unsupported in your environment, use the authentication mechanism documented by your provider or browser setup. Confirm the protected content is actually present before taking the image; merely calling the screenshot method does not authenticate a 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 matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #3
Save the right kind of screenshot
Current window or viewport
driver.save_screenshot("screenshot.png") captures the current browsing context to a PNG file and returns a success value. Selenium’s WebDriver documentation describes the screenshot endpoint response as Base64-encoded; the Python convenience method saves the image directly to the file path you provide. The generic method should not be treated as a full-document screenshot API.
Full-document capture in Firefox
The Selenium Python Firefox driver separately documents get_full_page_screenshot_as_file and save_full_page_screenshot for full-document screenshots. These are Firefox-driver methods, so use them only in a supported Firefox setup; do not assume they are available through Chrome’s driver. Consult the Selenium Firefox WebDriver API documentation for the specific method signatures.
Rank #4
Troubleshoot failed or misleading captures
- The browser shows an authentication prompt or an error page: URL credentials may be unsupported or malformed. Check the target browser/provider’s supported authentication route, and verify that special characters in credentials are encoded correctly.
- The screenshot saves but contains a login or error page: the capture call can succeed even when authentication fails. Wait for an authenticated-only element, and investigate redirects or provider-specific authentication requirements.
- The wait times out: the selector may not exist on that page, may be hidden, or the page may not have reached the expected state. Replace
mainwith a reliable element for the protected content and choose a timeout appropriate to the application. - The screenshot method returns
False: treat the save as a failure rather than assuming the file is valid; check the output path and the process’s ability to write there. - The image omits content farther down the page: the generic screenshot captures the current window, not necessarily the entire document. Use a supported Firefox full-page method when that is the needed output.
- Credentials appear in logs or artifacts: stop sharing the affected output, rotate exposed test credentials where appropriate, and avoid logging or publishing credential-bearing URLs.
Or skip the browser setup
For a page that ScreenshotNeo can access, its one-request API returns a screenshot. This example saves a WebP capture of a public URL:
Quick Recap
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.test -o shot.webp
See the ScreenshotNeo API documentation for request options. Cookie banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, timeouts, and failed loads are not billed. Its MCP server gives AI agents screenshot, page-info, and PDF-capture tools. The free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000 shots. This example does not itself supply HTTP Basic credentials; consult the API documentation for supported request options before using it with a protected page. Learn about ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.
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.

