等待驾驶 IE“您确定要离开此页面吗?”弹出窗口

发布于 2025-01-06 01:16:34 字数 648 浏览 1 评论 0 原文

我想扩展我的 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());

谢谢!

I'd like to extend my WatiN automated tests to drive a page that guards against the user accidentally leaving the page without saving changes.

The page uses the "beforeunload" technique to seek confirmation from the user:

$(window).bind('beforeunload', function (event) {
    if (confirmationRequired) {
        return "Sure??";
    }
});

My WatIn test is driving the page using IE. I cannot find a way to get WatIn to attach to the popup dialog so I can control it from my test.

All the following have failed (where the hard-coded strings refer to strings that I can see on the popup):

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());

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白首有我共你 2025-01-13 01:16:34

您需要创建并添加对话框处理程序。

示例 转到示例站点,单击链接,单击确认对话框中的离开页面:

IE browser = new IE();
browser.GoTo("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onbeforeunload.htm");

WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9 myHandler = new WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9();

browser.AddDialogHandler(myHandler);
browser.Link(Find.ByUrl("http://www.microsoft.com")).ClickNoWait();
myHandler.WaitUntilExists();

myHandler.OKButton.Click();
browser.RemoveDialogHandler(myHandler);

以上适用于 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:

IE browser = new IE();
browser.GoTo("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onbeforeunload.htm");

WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9 myHandler = new WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9();

browser.AddDialogHandler(myHandler);
browser.Link(Find.ByUrl("http://www.microsoft.com")).ClickNoWait();
myHandler.WaitUntilExists();

myHandler.OKButton.Click();
browser.RemoveDialogHandler(myHandler);

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文