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 ...
source share