Selenium Screenshot After Login for an Indian Banking Web Portal
Capture a Selenium screenshot after an approved banking test login. Learn how to wait for the authenticated page, save the PNG, and protect it.
To take a Selenium screenshot after logging in to an Indian banking web portal, first use an approved test environment and account, then wait for a page condition that confirms the authenticated view is ready, and save the current browser window as a PNG. The exact login steps and readiness selector depend on the portal; do not guess selectors or automate a real customer account.
This guide shows the pattern in Python with Selenium, explains when to exercise the login UI versus establish test state through an approved route, and covers screenshot checks and safe handling. No bank portal or live login is assumed or tested.
1. Confirm the portal and test account are approved
Before automating a banking portal, confirm that its owner permits the test and that the account is intended for automation. Use a dedicated test environment and synthetic or otherwise approved test data where available. A generic Selenium recipe does not establish that a particular bank allows browser automation.
Never put real customer credentials, session cookies, OTPs, PINs, or other payment credentials in source code, logs, screenshots, or shared test artifacts. The Reserve Bank of India (RBI) tells consumers not to share passwords, PINs, OTPs, CVVs, or UPI PINs, and to use verified, secure banking sites. That consumer guidance does not authorize automation.
2. Choose how the test establishes login state
| Approach | Use it when | Requirements and tradeoffs |
|---|---|---|
| Exercise the login UI | The test needs to verify the login journey itself or the portal has no approved state setup route. | Use permitted test credentials and only bank-supported test arrangements for MFA. Login UI tests cover more of the journey, but can be affected by authentication steps and changing page behavior. |
| Set up state through an approved test API | The test is about the page after login and repeated UI logins add instability. | The application must provide and permit a suitable test route. Selenium gives API login followed by setting a cookie as an example of preparing state outside browser interactions. This is not a way to bypass a bank’s authentication controls. |
Selenium’s test-practice guidance says, “Selenium should not be used to prepare a test case.” Its example is to use an API to log in and set a cookie when the application supports that approach. Read the [Selenium guidance on generating application state](https://www.selenium.dev/documentation/test_practices/encouraged/generating_application_state/) and follow the application’s security design.
If an approved setup requires adding a cookie, first navigate to the matching domain: WebDriver accepts a cookie in the relevant browsing context and domain. Do not copy cookies from a real user session. See Selenium’s [cookie documentation](https://www.selenium.dev/documentation/webdriver/interactions/cookies/).
3. Install Selenium and configure a browser
The following example uses Python and Selenium 4. It assumes a browser and a compatible driver are available in the test environment. Selenium WebDriver drives a real browser locally or remotely; the browser and driver setup are environment-specific. Consult the [Selenium overview](https://www.selenium.dev/documentation/overview/) and your browser’s supported setup instructions.
python -m pip install "selenium>=4,<5"
Set the test URL and credentials through your approved test secret mechanism. The placeholder URL and selectors below are deliberately not bank-specific: replace them with values documented for your test environment. Do not print credentials or include them in exception messages.
4. Log in, wait for the authenticated page, and save a screenshot
Use an explicit wait for an observable condition that means the intended authenticated page is ready, such as a stable dashboard landmark or account-summary container defined by your test environment. A completed navigation alone does not prove a JavaScript-heavy page has finished rendering. Avoid guessed fixed sleeps, and do not mix implicit waits with explicit waits; Selenium documents that dynamic content can arrive after document readiness and that mixing wait strategies can produce unpredictable timing.
import os
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
portal_url = os.environ["TEST_PORTAL_URL"]
test_username = os.environ["TEST_USERNAME"]
test_password = os.environ["TEST_PASSWORD"]
# Replace these with selectors and routes approved for your test portal.
username_selector = (By.NAME, "test-username")
password_selector = (By.NAME, "test-password")
submit_selector = (By.CSS_SELECTOR, "button[type='submit']")
logged_in_selector = (By.CSS_SELECTOR, "[data-test='authenticated-home']")
screenshot_path = Path("artifacts/banking-portal-after-login.png")
options = webdriver.ChromeOptions()
# For a remote grid, use Remote WebDriver and the grid's approved endpoint
# instead of webdriver.Chrome().
driver = webdriver.Chrome(options=options)
try:
driver.implicitly_wait(0) # Use explicit waits consistently.
driver.set_window_size(1440, 1000)
driver.get(portal_url)
wait = WebDriverWait(driver, 30)
wait.until(EC.visibility_of_element_located(username_selector)).send_keys(test_username)
wait.until(EC.visibility_of_element_located(password_selector)).send_keys(test_password)
wait.until(EC.element_to_be_clickable(submit_selector)).click()
# This must identify the expected authenticated view in your test app.
wait.until(EC.visibility_of_element_located(logged_in_selector))
screenshot_path.parent.mkdir(parents=True, exist_ok=True)
saved = driver.save_screenshot(str(screenshot_path))
if not saved or not screenshot_path.is_file() or screenshot_path.stat().st_size == 0:
raise RuntimeError("WebDriver did not save a non-empty screenshot")
finally:
driver.quit()
The example checks Selenium’s Boolean save result and verifies that a non-empty file exists. The Python WebDriver API documents save_screenshot(filename) and get_screenshot_as_file(filename) as ways to save the current window to PNG. See the [Python WebDriver screenshot API](https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html). If using another language binding, use that binding’s documented screenshot method and check its result.
To capture the full page, first confirm the chosen browser and binding support the full-page behavior you need; a current-window screenshot may cover only the visible viewport. For repeatable test evidence, a viewport screenshot is often easier to compare. Do not add unsupported browser-specific commands without checking their current official documentation.
5. Make the readiness check meaningful
A useful wait checks a condition tied to the expected logged-in view. Examples include a portal-specific authenticated page landmark becoming visible, a known loading indicator disappearing, or a test-owned page state changing. Select a condition that cannot also be true on the login or error page.
- Do not treat
document.readyState == "complete"as proof that a dynamic dashboard is ready. - Prefer an explicit wait on a stable element or state that the application exposes for testing.
- Use a reasonable timeout based on the approved test environment, and let the wait fail with a useful test error instead of taking a screenshot of an unknown state.
- Do not combine implicit and explicit waits. Keep implicit waiting at zero when following the example above.
See Selenium’s official [waits documentation](https://www.selenium.dev/documentation/webdriver/waits/) for wait behavior and guidance.
6. Protect the screenshot artifact
A banking screenshot may reveal account identifiers, balances, transaction details, or personal data. Treat it as sensitive test data: restrict artifact access, avoid production customer information, redact details that are not needed for the test, and follow your organization’s retention policy. Consider whether the screenshot needs to be retained at all; a pass/fail assertion may be sufficient for some tests.
RBI internet-banking security material discusses protecting account data and client-side storage in its stated regulatory context. It should not be read as a new, universal technical specification for every bank or current portal. Follow the portal owner’s current test and data-handling rules.
7. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Element lookup fails on the login page | The example selector is a placeholder, the page has not rendered it, or the test is on the wrong route. | Use the selector documented for the approved test environment. Wait for visibility and confirm the current URL and page state without logging secrets. |
| Screenshot shows the login page or a loading view | The script captured after navigation rather than after the authenticated view became ready, or login did not succeed. | Wait for a portal-specific authenticated landmark; handle expected test MFA only through the approved flow. Fail the test if the condition never appears. |
| Wait times out | Wrong selector, rejected test credentials, an expected MFA step, a portal error, or delayed service response. | Inspect a restricted test-environment run, verify the approved account and route, and update the readiness condition to match the actual test state. Do not increase the timeout blindly. |
| Cookie setup is rejected | The browser is not on the cookie’s matching domain or the cookie is malformed or outside the permitted setup route. | Navigate to the correct test domain before adding it, and use only application-approved test state. Never source cookies from a real banking session. |
| Screenshot save returns false or file is empty | The target directory is unavailable, permissions are insufficient, or the browser session ended. | Create the directory, check the test runner’s write permissions, save before quitting the driver, and retain the Boolean and file-size checks. |
| Browser or driver fails to start | Browser and driver are missing, incompatible, or the remote grid configuration is incorrect. | Use the supported browser/driver setup for your Selenium environment and verify the approved grid endpoint and capabilities. |
| Test is flaky despite a fixed delay | Page readiness varies and the delay does not track the authenticated UI state. | Replace the sleep with an explicit wait for a stable, meaningful condition. Keep wait strategies consistent. |
| Artifact contains more personal data than required | The capture area or test data is broader than necessary. | Use synthetic test data, narrow the capture if supported by your binding, redact unnecessary details, limit access, and apply the retention policy. |
8. Performance, reliability, and cost
For speed and stability, keep the test focused on the behavior it needs to prove. If the login journey itself is not under test and an approved API can establish test state, that can avoid repeating browser setup interactions; it depends on application support and permission. Keep the readiness condition specific, and avoid capturing or retaining screenshots for every successful run if the artifact is not needed.
WebDriver controls a real browser, so execution time and reliability depend on browser startup, the portal, the test environment, and any remote grid. A saved screenshot is evidence of the rendered browser window at that moment; it does not independently prove that the account state or page data is correct. Add separate assertions for the state the test is meant to validate.
Cost depends on the browser infrastructure and artifact storage your test environment uses. This Selenium example makes no claims about portal performance or a particular provider’s pricing. Protecting and retaining sensitive images also has an operational cost, so keep only what the test policy requires.
9. Or skip the browser setup
If you need a clean screenshot of a public page rather than an authorized authenticated banking test, [ScreenshotNeo](https://screenshotneo.com) provides a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF. See the [ScreenshotNeo API documentation](https://screenshotneo.com/docs/) 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
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, 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 for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Do not use this public-page capture API as a way to automate or capture an authenticated banking session.
Sign up for 1,000 free screenshots a month, with no card required.
10. FAQ
Can I automate login to any Indian banking portal with Selenium?
No general permission can be assumed. Get explicit approval and use only the portal’s supported test environment, account, and authentication arrangements.
Can I take a screenshot after an MFA step?
Only when the portal owner provides an approved test flow for MFA. Do not bypass or weaken authentication controls to make a test pass.
Does the example capture a full-page image?
It saves the current browser window. Full-page capture support and behavior depend on the browser and Selenium binding; check the official documentation for the environment you use.
Can I use a real customer session cookie to skip login?
No. Use only an application-approved test-state mechanism and dedicated test data. A real session cookie is sensitive authentication material.


