等待驾驶 IE“您确定要离开此页面吗?”弹出窗口
我想扩展我的 WatiN 自动化测试来驱动一个页面,以防止用户意外离开页面而不保存更改。
该页面使用“beforeunload”技术来寻求用户的确认:
$(window).bind('beforeunload', function (event) {
if (confirmationRequired) {
return "Sure??";
}
});
我的 WatIn 测试正在使用 IE 驱动该页面。我无法找到一种方法让 WatIn 附加到弹出对话框,以便我可以从测试中控制它。
以下所有操作都失败了(其中硬编码字符串指的是我可以在弹出窗口中看到的字符串):
Browser.AttachTo<IE>(Find.ByTitle("Windows Internet Explorer");
browser.HtmlDialog(Find.FindByTitle("Windows Internet Explorer));
browser.HtmlDialog(Find.FindByTitle("Are you sure you want to leave this page?));
browser.HtmlDialog(Find.FindFirst());
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建并添加对话框处理程序。
示例 转到示例站点,单击链接,单击确认对话框中的离开页面:
以上适用于 WatiN2.1、IE9、Win7。如果使用 IE8 或更早版本,您可能需要使用
ReturnDialogHandler
对象而不是 Ie9 特定处理程序You'll need to create and add the dialog handler.
Example Go to example site, click link, click leave page on confirmation dialog:
The above is working on WatiN2.1, IE9, Win7. If using IE8 or before, you will likely need to use the
ReturnDialogHandler
object instead of the Ie9 specific handler