问题
I have a webpage that has an onbeforeunload script that prompts the user when they take an action that would navigate away from the current page.
How do I interact with this popup using Watir? My current approach looks like this:
$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")
The problem is that if I use "click no wait" the popup is not created, and the test times out. If I use "click" then the popup is created, but the test hangs after it opens.
Any suggestions?
回答1:
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
回答2:
This should do the trick closing this alert:
browser.alert.ok
See the Watir docs here.
来源:https://stackoverflow.com/questions/1758699/how-to-click-on-onbeforeunload-prompt-in-watir-test