如何在 Watir 测试中点击 onbeforeunload 提示? [英] How to click on onbeforeunload prompt in Watir test?

查看:22
本文介绍了如何在 Watir 测试中点击 onbeforeunload 提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

如何使用 Watir 与此弹出窗口交互?我目前的方法是这样的:

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.

有什么建议吗?

推荐答案

这应该可以关闭此警报:

This should do the trick closing this alert:

browser.alert.ok 

在此处查看 Watir 文档.

这篇关于如何在 Watir 测试中点击 onbeforeunload 提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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