selenium 2.4.0, how to check for presence of an alert

Here is one option:

driver.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError

This will click OK on the alert if one is present, else it will fail gracefully (silently).

Leave a Comment