如何使用 Capybara 确认 javascript 弹出窗口? [英] How do I confirm a javascript popup with Capybara?

查看:29
本文介绍了如何使用 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 年及以后遇到此问题的人添加答案.您现在可以直接使用 Capybara 来接受确认框.您可以通过包装导致确认框出现在 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 causes the confirmation box to appear in the accept_confirm function.

accept_confirm do
  click_link 'Destroy'
end

这篇关于如何使用 Capybara 确认 javascript 弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆