如何使用 watin 在警报对话框中单击“确定”按钮?

发布于 2024-11-25 17:33:41 字数 1102 浏览 1 评论 0原文

我正在尝试自动化一个网站,在我的项目中单击“提交”按钮后,会出现一条带有“确定”按钮的警报消息。我想点击那个确定按钮。

我分别尝试使用这两个代码,但它们不起作用

                    AlertDialogHandler AlertDialog = new AlertDialogHandler();
                    ie.AddDialogHandler(AlertDialog);
                    ie.Button(Find.ByValue("Submit")).ClickNoWait();
                    AlertDialog.WaitUntilExists();
                    AlertDialog.OKButton.Click();
                    ie.WaitForComplete();
                    ie.RemoveDialogHandler(AlertDialog);


                    var AlertDialogHandler = new AlertDialogHandler();
                    using (new UseDialogOnce(ie.DialogWatcher, AlertDialogHandler))
                    {
                        ie.Button(Find.ByValue("Submit")).ClickNoWait();
                        AlertDialogHandler.WaitUntilExists(50);
                        var message = AlertDialogHandler.Message;
                        AlertDialogHandler.OKButton.Click();
                        ie.WaitForComplete();
                    }

在使用这两个代码时,我得到了相同的异常“对话框在 30 秒内不可用”。

任何帮助将不胜感激。谢谢 :)

I am trying to automate one website, in my project after clicking on 'submit' button, one alert message with ok button will come. I want to click that ok button.

I tried with these two codes seperatly but these are not working

                    AlertDialogHandler AlertDialog = new AlertDialogHandler();
                    ie.AddDialogHandler(AlertDialog);
                    ie.Button(Find.ByValue("Submit")).ClickNoWait();
                    AlertDialog.WaitUntilExists();
                    AlertDialog.OKButton.Click();
                    ie.WaitForComplete();
                    ie.RemoveDialogHandler(AlertDialog);


                    var AlertDialogHandler = new AlertDialogHandler();
                    using (new UseDialogOnce(ie.DialogWatcher, AlertDialogHandler))
                    {
                        ie.Button(Find.ByValue("Submit")).ClickNoWait();
                        AlertDialogHandler.WaitUntilExists(50);
                        var message = AlertDialogHandler.Message;
                        AlertDialogHandler.OKButton.Click();
                        ie.WaitForComplete();
                    }

While using these two codes, I got the same exception 'dialog not available within 30 seconds'.

Any help will be deeply appreciated. Thank You :)

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

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

发布评论

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

评论(4

十雾 2024-12-02 17:33:41

当我打开多个浏览器窗口并尝试时,这种情况发生过几次。

当时的解决方案是关闭 IE 的所有实例,关闭 NUnit / VS 并重新开始,这非常有效。但是,我使用的是ConfirmDialogHandler 而不是AlertDialog Handler。

如果这没有帮助,您可能需要在启动浏览器实例之前尝试添加以下内容。

Settings.AutoStartDialogWatcher = true;
Settings.AutoCloseDialogs = true;

This has happened with me a couple of times when I had multiple browser windows open and I was trying it out.

The solution at that time was to close all instances of IE, close NUnit / VS and start over again, and it worked like a charm. However, I was using a ConfirmDialogHandler and not an AlertDialog Handler.

If that does not help you might want to try adding the following before you fire up your browser instance.

Settings.AutoStartDialogWatcher = true;
Settings.AutoCloseDialogs = true;
↙温凉少女 2024-12-02 17:33:41

我不熟悉 WatiN,但这里有另一篇可能有帮助的帖子:

WatiN似乎没有找到 JavaScript 警报

I'm not familiar with WatiN, but here's another SO post that might help:

WatiN seems to not find JavaScript alert

如日中天 2024-12-02 17:33:41

有一种方法可以在不等待的情况下执行此操作:

请参阅我的帖子:

需要一种方法来对 Firefox 或任何其他浏览器弹出窗口执行自动确认

There is a way to perform this without watin:

See my post:

Need a way to perform auto confirm for firefox or any other browser popup's

空宴 2024-12-02 17:33:41

这有点不相关,但 AlertDialogHandler 不适用于 Firefox,但有一个解决方法...

http://pastebin.com/ZapXr9Yf

this is slightly unrelated but AlertDialogHandler's don't work for Firefox but there is a workaround...

http://pastebin.com/ZapXr9Yf

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