【问题标题】:Watir handling multiple popups one after anotherWatir一个接一个地处理多个弹出窗口
【发布时间】:2014-05-29 02:21:56
【问题描述】:

我有一个场景,其中单击一个按钮时,屏幕上会出现第一个弹出窗口,带有一个确定和一个取消按钮。单击第一个弹出窗口的 ok 按钮后,第二个弹出窗口会出现一个 ok 和一个取消按钮。

这里的问题是我无法点击第二个弹出窗口的确定按钮。

用于点击的代码如下。第一个弹出的ok按钮点击成功。

browser.button(:text, "Try it").click_no_wait

browser.alert.ok #here first alert ok button is clicked

如果我再次使用browser.alert.ok 进行第二次警报,脚本会挂起

【问题讨论】:

  • 添加有关您使用的技术的标签。

标签: java internet-explorer popup alert watir


【解决方案1】:

问题

问题似乎是 Watir-Classic 如何处理等待警报消失的问题。当你执行browser.alert.ok时,它会点击按钮,然后调用wait_until_not_exists

def wait_until_not_exists
  Wait.until(3) {!exists?}
  @container.page_container.wait
end 

此方法等待警报消失,然后浏览器完成加载。

经过一些测试,看起来等待浏览器完成加载并不能说明正在显示的警报。该警报阻止 Watir 相信页面已加载,因此最终会超时。

解决方法

最好的解决方案可能是更新 Browser#wait 方法。但是,我不确定要更改什么或影响。

另一种方法是只修改 wait_until_not_exists 方法。这种方法使用较少,因此可能是较低风险的变化。当需要 Watir-Classic 时,您可以添加以下猴子补丁:

require 'watir-classic'

module Watir
  class Alert
    def wait_until_not_exists
      Wait.until(3) {!exists?}
      unless @container.page_container.alert.exists?
        @container.page_container.wait
      end
    end   
  end
end

这里我们将等待方法更改为仅在没有其他警报存在时才等待页面加载。

有了这个补丁,你点击两个警报的代码应该可以工作了:

browser.alert.ok    
browser.alert.ok

【讨论】:

  • 这正在工作。感谢您的回复 - 迪皮卡
猜你喜欢
  • 2012-12-12
  • 2015-02-09
  • 1970-01-01
  • 1970-01-01
  • 2019-04-14
  • 1970-01-01
  • 2015-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多