selenium 2.4.0, how to check for presence of an alert

0
0

Before using selenium 2.4.0 I had the following code working:

alert = page.driver.browser.switch_to.alert
if alert.text
....
end

Selenium 2.4.0 contains the change “* Raise in switch_to.alert when no alert is present.”, so I get a No alert is present (Selenium::WebDriver::Error::NoAlertOpenError) exception.

How can I check for the presence of an alert with selenium-web-driver 2.4.0?

  • You must to post comments
0
0

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).

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website