medium

UnexpectedAlertPresentException

A JavaScript alert, confirm, or prompt dialog appeared unexpectedly, blocking automation. Selenium cannot interact with the page until the alert is dismissed.

Common Causes

  1. 1Application shows a confirm dialog before navigation
  2. 2JavaScript error triggered an alert
  3. 3Form submission shows a validation alert
  4. 4Session timeout alert appeared

How to Fix

Handle the alert explicitly

// Python
from selenium.webdriver.common.alert import Alert

alert = Alert(driver)
print(alert.text)  # Read alert text
alert.accept()     # Click OK
# or
alert.dismiss()    # Click Cancel

Use the Alert class to inspect and handle JavaScript dialogs.

Set unexpected alert behavior in capabilities

// Python
from selenium.webdriver.chrome.options import Options

options = Options()
options.set_capability('unhandledPromptBehavior', 'accept')
driver = webdriver.Chrome(options=options)

Automatically accept all alerts. Useful when you don't care about alert content.

How ObserveOne Helps

ObserveOne monitors browser dialogs and handles unexpected alerts automatically during test execution.

Start Monitoring Free

Related Errors