如何使用Capybara确认JavaScript弹出窗口? [英] How do I confirm a javascript popup with Capybara?
本文介绍了如何使用Capybara确认JavaScript弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了几个在网上找到的示例,但是没有运气。我正在寻找确认删除链接的确认消息。上一次尝试是下面的代码,但这导致了Capybara :: NotSupportedByDriverError错误。
I've tried several examples found online, but with no luck. I am looking to confirm the confirm message of a delete link. The last attempt was the code below, but that resulted in an Capybara::NotSupportedByDriverError error.
def confirm_dialog
page.evaluate_script('window.confirm = function() { return true; }')
end
推荐答案
为2016年及以后实现这一目标的人添加答案。现在,您可以直接使用水豚来接受确认框。通过包装使确认框显示在 accept_confirm 函数中的代码来完成此操作。
Adding an answer for those hitting this in 2016 and beyond. You can now use Capybara directly to accept a confirmation box. You do this by wrapping the code that cause the confirmation box to appear in the accept_confirm function.
accept_confirm do
click_link 'Destroy'
end
这篇关于如何使用Capybara确认JavaScript弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文