Dealing with: Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)

If your Cucumber test encounters a javascript alert in the browser, it will throw this sort of error.

Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)
[remote server] file:///var/folders/s0/xyrbzq_j7h32jq4n3g53c2kc0000gp/T/  ...

To avoid this error, you have to close the alert message. In the custom steps file, for the particular step that’s throwing the error, add this line.

page.driver.browser.switch_to.alert.accept
page.driver.browser.switch_to.alert.dismiss

accept will click “OK” and dismiss will click “Cancel”.

This was posted 6 months ago. It has 0 notes.