English 中文(简体)
How to click on onbeforeunload prompt in Watir test?
原标题:

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?

问题回答

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

This should do the trick closing this alert:

browser.alert.ok 

See the Watir docs here.





相关问题
页: 1

在用户离开网页时,我只想在网页上提交几种表格。 是否有这种“你拯救吗?”的问题,而我迄今为止的法典就是这样:

Javascript synchronous AJAX timeout

My Javascript needs to send some data to a server when the page closes, which I currently do with a synchronous AJAX (SJAX?) request in window.onbeforeunload. The problem with this, of course, is that ...

jQuery UI Dialog OnBeforeUnload

I have a small problem. I m attempting to catch the OnUnLoad Event of the Window and ask a confirmation question and if the user decides they want to stay then fine, and if they want to leave the ...

How to click on onbeforeunload prompt in Watir test?

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 ...

window.onbeforeunload not firing in child window

I want to bind a function to the beforeunload event of a child window in Javascript. I have the following code: newWind = window.open(settings.url, "Dialog", "width=" + settings.width + ",height=" + ...

热门标签