Free tools Windows power users keep installed
One-click scans. No signup required.
First identify what kind of popup you have: use WebDriver’s alert API for JavaScript alerts, confirms, and prompts; switch window handles for a new tab or window; and use ordinary element locators and waits for an HTML modal inside the page. An operating-system dialog is a different case: neither the alert API nor window handles are a general way to control it.
Identify the popup before choosing an API
“Popup” can mean several different things in a browser test, and the handling method depends on which one appeared. Selecting the wrong context is a common source of errors such as “no alert present” and “no such window.”
| What appeared | How WebDriver represents it | What to do |
|---|---|---|
| JavaScript alert, confirm, or prompt | A modal dialog exposed through the alert API | Wait for the alert, read its text if needed, then accept or dismiss it. For a prompt, enter text before accepting. |
| New browser tab or window | A browsing context identified by a window handle | Wait for the new handle, switch to it, interact there, and return to a still-open handle when finished. |
| HTML/CSS modal within the page | Ordinary page content in the current document | Find its controls as page elements and wait for the required state before interacting. |
| Operating-system dialog | Outside the browser-page alert and window-handle procedures | Do not assume WebDriver’s alert or window APIs can operate it. A browser- or environment-specific integration may be needed. |
Selenium’s documentation describes the alert API for JavaScript alerts, prompts, and confirmations, and window handles for tabs and windows. It does not provide a dedicated HTML-modal recipe on those popup pages; treating a page modal as ordinary DOM content follows from the distinction between a browser dialog and the current document.
Handle JavaScript alerts, confirms, and prompts
Use WebDriver’s alert object, not DOM locators for the dialog’s buttons. An alert presents a message and an OK-style action; a confirm can be accepted or dismissed; a prompt also has a text field. The API lets you read the message, accept or dismiss the dialog, and set prompt response text.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11#1 Best Overall
Python: wait for an alert and accept it
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
alert = wait.until(EC.alert_is_present())
message = alert.text
alert.accept() # or alert.dismiss()
alert_is_present() is the expected condition for synchronizing with a JavaScript alert. The example assumes driver has already been created and the test has triggered the action that opens the dialog. Keep the wait near that action so the test waits for the popup it expects, rather than trying to acquire an alert at an unrelated point.
Python: respond to a prompt
alert = WebDriverWait(driver, 10).until(EC.alert_is_present())
alert.send_keys("response text")
alert.accept()
Enter the response before accepting. If the test needs to verify prompt behavior when the user cancels instead, call alert.dismiss() rather than accepting it.
JavaScript: read and accept an alert
const alert = await driver.switchTo().alert();
const message = await alert.getText();
await alert.accept(); // or await alert.dismiss()
This is the JavaScript binding pattern. If the dialog appears asynchronously, put alert acquisition behind a wait or retry strategy appropriate to the test. Calling switchTo().alert() immediately, before the page has opened the dialog, can fail because no alert is present yet.
Rank #2
Account for beforeunload prompts
Recent drivers automatically dismiss beforeunload prompts by default, according to Selenium’s alerts guide. If a test depends on the previous handling behavior, configure the session’s unhandledPromptBehavior deliberately. Treat it as a driver/session policy: it affects what happens when a prompt is left unhandled, rather than serving as a locator for a particular popup.
Switch to a popup tab or window
A tab or separate window is a browsing context, not a JavaScript alert. WebDriver identifies each context with a unique, persistent window handle; its API does not distinguish tabs from windows. Save the current handle and the existing handle set before triggering the popup. After it opens, find the new handle by comparing sets, switch to it, and restore a valid handle after closing it.
Python: switch to a tab or window opened by a link
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
original = driver.current_window_handle
before = set(driver.window_handles)
driver.find_element(By.LINK_TEXT, "Open new window").click()
wait.until(EC.number_of_windows_to_be(len(before) + 1))
new_handle = (set(driver.window_handles) - before).pop()
driver.switch_to.window(new_handle)
# interact with the popup page
driver.close()
driver.switch_to.window(original)
Replace the link text with a locator that matches the page under test. Waiting for the count to rise by one is suitable when the action is expected to open exactly one context. If you want to wait for a new handle relative to the saved set instead of asserting that exact count, use EC.new_window_is_opened(before).
Rank #3
Only call driver.close() if the test is meant to close the child context. If you close it, switch back to a handle that still exists before issuing further commands. Otherwise the driver may remain on a closed page and raise a No Such Window Exception.
Selenium 4: create a new context yourself
driver.switch_to.new_window('tab')
# the new tab is already selected
driver.switch_to.new_window('window')
# the new window is already selected
Use this when the test needs to create a browsing context directly rather than detect one opened by the page. Selenium’s documentation identifies switch_to.new_window('tab') and switch_to.new_window('window') as Selenium 4-and-later functionality; after either call, the new context is selected.
Handle an HTML modal in the current page
An HTML/CSS modal is part of the page document. It may look like a popup, but it is not the WebDriver alert object and does not require switching to another window handle. Locate the modal’s buttons or fields with ordinary page locators, then wait for the state the interaction requires—such as visibility or clickability—before clicking or entering text.
Rank #4
Use selectors that identify the modal or its controls reliably, especially if the page has similarly named buttons elsewhere. If a click does not work, check whether the modal is actually present and visible in the current page, whether an overlay blocks the target, and whether the test is still in the expected window context. The official Selenium popup pages discussed here do not prescribe a dedicated modal API.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Why popup handling fails, and how to recover
“No alert present”
This means WebDriver could not acquire an alert at the point the command ran. The action may not have triggered a JavaScript dialog, the dialog may not have appeared yet, or the supposed popup may actually be a page modal or a new browsing context. Confirm the popup type, trigger it, and wait with EC.alert_is_present() before reading or accepting it. For a DOM modal, use an element wait; for a new tab or window, wait for its handle instead.
The wait for a new window times out
The expected context did not appear within the wait. Check that the trigger action actually ran and that opening a new tab or window is the page’s behavior. If exactly one new context is expected, number_of_windows_to_be(len(before) + 1) checks that count; if your condition is specifically that a handle has been added to the prior set, use new_window_is_opened(before). Do not try to solve a missing browser context with the alert API.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteBest Value
“No Such Window Exception” after closing a popup
A command may be targeting a context that has already been closed. Keep the original handle, close the child only when appropriate, and switch back to the still-valid original handle before continuing. If the original context was also closed, select another handle that is still present rather than reusing a stale handle.
The popup is visible, but Selenium cannot find its buttons
If the dialog is a native JavaScript alert, its controls are not ordinary page elements: use the alert object. If it is an HTML modal, locate its controls in the page DOM. If it is an operating-system dialog, the browser-page alert and window-handle procedures described here do not establish a way to control it.
Or skip the browser setup
If your goal is a clean screenshot of a webpage rather than interacting with its popup, ScreenshotNeo can return an image or PDF from one GET request. It is a screenshot API and MCP server, not a Selenium replacement: use Selenium when the test must act on a dialog or page; use the API when you need a captured page without setting up a browser yourself.
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 request options. Cookie banners are accepted before capture, and 60+ known consent platforms, newsletter popups, and chat widgets are removed; each of those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. An MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
FAQ
Can WebDriver tell whether a new context is a tab or a window?
No. WebDriver exposes both through window handles and does not distinguish the two in this API.
Can I use Selenium 4 to open a new tab directly?
Yes. Call driver.switch_to.new_window('tab'); WebDriver selects the new tab.
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.
Recommended Free Tools




