elements / pop-up
Single UI element
Pop-up & Dialogs
An in-page HTML modal dialog versus a native browser confirm() alert — two distinct automation patterns.
In-page modal
#btn-open-modal- trigger id
- btn-open-modal
- modal id
- #confirm-modal
- actions
- #modal-cancel, #modal-confirm
- expected
- Opens a dialog rendered in the same DOM with Cancel / Confirm buttons.
Code snippets
Python (Selenium)
driver.find_element(By.ID, "btn-open-modal").click()
modal = WebDriverWait(driver, 2).until(
EC.visibility_of_element_located((By.ID, "confirm-modal"))
)
driver.find_element(By.ID, "modal-cancel").click()TypeScript (Playwright)
await page.click('#btn-open-modal');
await page.waitForSelector('#confirm-modal.open');
await page.click('#modal-cancel');Native confirm()
#btn-native-confirm- id
- btn-native-confirm
- output
- #native-confirm-out
- expected
- Triggers the browser's own
confirm()dialog — automation tools must handle it via dialog listener or switch_to.alert.
Code snippets
Python (Selenium)
driver.find_element(By.ID, "btn-native-confirm").click()
alert = driver.switch_to.alert
assert "Leave without saving" in alert.text
alert.accept() # or alert.dismiss()
assert driver.find_element(By.ID, "native-confirm-out").text == "confirmed"TypeScript (Playwright)
page.on('dialog', async dialog => await dialog.accept());
await page.click('#btn-native-confirm');
expect(await page.textContent('#native-confirm-out')).toBe('confirmed');Delete this account?
This action can't be undone. All associated test data will be removed.