How to screenshot a logged-in IRCTC account page with Selenium
Use an authenticated Selenium browser, wait for the IRCTC account content you need, then save a window or element screenshot. Includes runnable Python examples and troubleshooting.
To screenshot a logged-in IRCTC account page with Selenium, use a browser session in which the account holder has already signed in through the site’s normal flow. Navigate to the account page, wait until a confirmed account-page element is visible, then save the current browser window as a PNG with driver.save_screenshot(). If you need just one panel, take a screenshot of that element instead.
The page URL and CSS selector in the examples below are placeholders. Confirm both against the live IRCTC page before running the script. This guide does not provide an automated IRCTC login method or a way to bypass CAPTCHA or other access controls.
What Selenium captures
Selenium’s window screenshot methods save the current browser window. The documented method does not establish that it captures an entire long page beyond the viewport, so treat the result as a current-window screenshot. Selenium also supports screenshots of individual elements when you need a narrower capture. See the official Selenium windows and tabs documentation.
| Capture method | Use it for | Scope |
|---|---|---|
driver.save_screenshot(path) |
The account page as currently shown in the browser window | Current window |
element.screenshot(path) |
A specific account panel, card, or other visible component | One element |
Before you start
- Install Python and Selenium, and make sure a compatible browser and Selenium driver setup are available. Selenium’s WebDriver overview explains the browser automation model.
- Open or start a browser session and sign in through the normal IRCTC site flow. This example starts a new Chrome session, so sign in manually when the browser opens if prompted.
- Find a stable element that appears only when the account page is ready. Inspect the current live DOM and replace
YOUR_ACCOUNT_PAGE_READY_SELECTORwith its CSS selector. - Choose a destination path where the screenshot can be stored privately. Account pages may contain personal information.
Do not put account passwords or session cookies in source code, screenshots, logs, or shared examples. IRCTC’s privacy policy describes cookies as supporting a personalized experience and notes that deleting them can remove preferences or affect service availability.
Runnable Python example: current browser window
Install Selenium with python -m pip install selenium. Then save the following as capture_irctc.py. Replace the URL and selector placeholders after checking the live page.
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
ACCOUNT_PAGE_URL = "IRCTC_ACCOUNT_PAGE_URL"
READY_SELECTOR = "YOUR_ACCOUNT_PAGE_READY_SELECTOR"
OUTPUT_PATH = Path("irctc-account.png")
options = webdriver.ChromeOptions()
# Keep the browser visible so you can complete any normal sign-in steps.
driver = webdriver.Chrome(options=options)
try:
driver.get(ACCOUNT_PAGE_URL)
wait = WebDriverWait(driver, 20)
# If sign-in is required, complete it manually in the opened browser.
# Then wait for a page-specific element that you confirmed in the live DOM.
wait.until(
EC.visibility_of_element_located((By.CSS_SELECTOR, READY_SELECTOR))
)
OUTPUT_PATH.parent.mkdir(parents=True, exist_ok=True)
saved = driver.save_screenshot(str(OUTPUT_PATH))
if not saved:
raise RuntimeError(f"Selenium did not save the screenshot to {OUTPUT_PATH}")
print(f"Saved screenshot: {OUTPUT_PATH.resolve()}")
finally:
driver.quit()
driver.save_screenshot() returns a success value. The finally block closes the browser even if navigation, waiting, or saving fails. If you need to inspect the page after a timeout, temporarily remove driver.quit() or add a breakpoint while developing; do not leave a production process hanging indefinitely.
Capture one account element
Use an element screenshot when a full browser window would include unrelated content. The selector must identify the element you intend to capture, and the element must be visible before calling screenshot().
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
account_panel = wait.until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "YOUR_PANEL_SELECTOR"))
)
account_panel.screenshot("irctc-account-panel.png")
This snippet uses the same authenticated driver and wait from the preceding example. Element screenshots are useful for a card or panel; they do not substitute for a full-page capture when content extends beyond that element.
Wait for the account content, not just navigation
A navigation call can return when the document reaches its configured ready state even though JavaScript is still changing the page or revealing the account content. Use an explicit wait for a meaningful condition, such as visibility of an account heading or panel. Selenium’s waiting strategies documentation describes explicit waits as polling until the requested condition succeeds or times out.
Prefer a page-specific condition over a fixed sleep. A fixed delay can be too short on a slow load and unnecessarily long on a fast one. Selenium also warns: “Do not mix implicit and explicit waits.” Mixing them can produce unpredictable wait times. Use explicit waits consistently in this workflow.
IRCTC-specific limits and safe handling
- The current IRCTC account URL and page markup are not specified here. Follow the normal site flow to reach the page rather than assuming a route.
- No stable IRCTC CSS selector is established by the cited sources. Inspect the current page and choose a selector that matches the account content you need.
- This workflow assumes the account holder can access the page normally. It does not automate credentials, export cookies, or bypass CAPTCHA or other access controls.
- The IRCTC policy discusses cookies generally; it does not document Selenium integration or a supported automated login procedure.
- Protect the resulting PNG as you would other account data. Avoid committing it to a repository or attaching it to logs or tickets that are broadly accessible.
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
TimeoutException while waiting |
The selector is wrong, the account page is not open, sign-in has not completed, or the target content did not become visible before the timeout. | Confirm the URL and selector in the live DOM, complete the normal sign-in flow, and wait for a visible page-specific element. Increase the timeout only if the page legitimately needs longer. |
| Screenshot shows a sign-in page or loading state | The capture ran before the account content was ready, or the browser session is not authenticated. | Complete sign-in normally and make the wait condition identify the actual account content rather than a generic document element. |
| Screenshot file is missing or empty | The output path may be invalid or unwritable, or the save call returned failure. | Use an absolute or known writable path, create its parent directory, check the Boolean result from save_screenshot(), and inspect the raised error. |
| Chrome does not start | The browser or driver setup is unavailable or incompatible with the environment. | Install a supported browser and follow Selenium’s current WebDriver setup guidance; check the full startup exception for the missing component. |
| Screenshot misses content lower on a long page | The documented window method captures the current browser window, not a guaranteed full-page image. | Capture the relevant visible element, or use a separately documented full-page capture method appropriate to your browser and requirements. Do not assume save_screenshot() includes content outside the viewport. |
| Wait durations behave unpredictably | Implicit and explicit waits may have been combined. | Remove implicit waits and use explicit condition-based waits for this workflow. |
Performance, reliability, and cost
A local Selenium capture has no per-screenshot API charge, but it uses browser resources and requires a working browser environment. Capture time depends on navigation, sign-in state, page scripts, and the readiness condition. An explicit wait with a sensible timeout improves reliability by tying capture to page state; it cannot make a changed selector or inaccessible page succeed.
For repeatable captures, keep the readiness selector narrowly tied to the desired account content, write files to a controlled location, and handle navigation and timeout errors. The account session itself is sensitive: use a private browser profile and protect any screenshots that reveal personal details.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. A single request can return an image or PDF, and its supported parameters include custom headers, cookies, and authorization for pages you are allowed to access. See the ScreenshotNeo API documentation before using it with a private account page; never expose credentials or session data in public code.
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,
)
r.raise_for_status()
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}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
Replace the example URL with a page the account holder is authorized to access. For private pages, review the documentation for the appropriate authentication parameters and protect the API key and any account credentials. ScreenshotNeo removes cookie banners, popups, and chat widgets before the shot. Bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.
FAQ
Can Selenium take a screenshot after I sign in manually?
Yes. Keep the browser session open, complete the normal sign-in flow, and let the script wait for the account content before capture.
Does save_screenshot() capture the whole long page?
The cited Selenium documentation describes a screenshot of the current window. It does not establish full-page capture beyond the viewport.
Can I save only one account panel?
Yes. Locate the panel and call its element-level screenshot() method after waiting for it to become visible.
What should I do if the IRCTC page changes?
Reinspect the live DOM and update the readiness and target selectors. The examples intentionally use placeholders because a verified stable selector is not available here.


