Capybara switch_to.alert (dialog box) intermittent failure

I am trying to interact with a dialog box in FF using RSPEC / Capybara.

Found an elegant solution in: How to check confirmation dialog with Cucumber?

page.driver.browser.switch_to.alert.accept 

However, we get intermittent failures when the switch does not occur.

Has anyone come across this? In any case, so that the switch is always successful?

Thanks!

+4
source share
1 answer

As the answer says, the browser becomes irrelevant when the modal warning / confirmation / prompt dialog boxes open. Currently, despite the fact that browsers have learned to display modeless windows, Capybara still cannot evaluate any code in the context of the page.

As the related answer says, just close the window.confirm method. This is the best stable way.

You can write the following two steps in Capybara:

 When /I ensure the confirm box returns OK/ do page.evaluate_script('window.confirm = function() { return true; }') end When /I ensure the confirm box returns Cancel/ do page.evaluate_script('window.confirm = function() { return false; }') end 

Then you can start rewriting the steps of Capybara, so first make sure you drown the confirmation window, and then click on the link that brings up the confirmation window:

 When I ensure the confirm box returns OK And I click on Remove Then ... 
0
source

All Articles