0

我有一个网页,其中有一个 onbeforeunload 脚本,当用户采取离开当前页面的操作时,该脚本会提示用户。

如何使用 Watir 与此弹出窗口进行交互?我目前的方法如下所示:

$ie.link(:text, 'Dashboard').click_no_wait

hwnd = $ie.enabled_popup(10)
assert(hwnd, 'The expected \'leave this page?\' popup was not shown')

win = WinClicker.new
win.makeWindowActive(hwnd)
win.clickWindowsButton_hwnd(hwnd, "OK")

问题是,如果我使用“单击不等待”,则不会创建弹出窗口,并且测试会超时。如果我使用“单击”,则会创建弹出窗口,但测试在打开后会挂起。

有什么建议么?

4

2 回答 2

0

Do you want to assert dialog message?
I try your code, but could not find solution.
This is to try to catch dialog then when popup,get msg while 5sec. polling per 1sec.

$ie.link(:text, 'Dashboard').click_no_wait
@autoit = WIN32OLE.new('AutoItX3.Control')
  5.times do
    if @autoit.WinWait('Windows Internet Explorer','',1)==1 then
      @autoit.WinActivate('Windows Internet Explorer',"")
      @dialog_text = @autoit.WinGetText('Windows Internet Explorer',"")
      dialog_pop = "YES"
      break
    else
      sleep(1)
      dialog_pop = "NO"
    end
  end
于 2010-03-24T19:12:55.850 回答
0

这应该可以关闭此警报:

browser.alert.ok 

请参阅此处的 Watir 文档

于 2018-04-16T11:23:06.343 回答