如何使用 watin 在警报对话框中单击“确定”按钮?
我正在尝试自动化一个网站,在我的项目中单击“提交”按钮后,会出现一条带有“确定”按钮的警报消息。我想点击那个确定按钮。
我分别尝试使用这两个代码,但它们不起作用
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当我打开多个浏览器窗口并尝试时,这种情况发生过几次。
当时的解决方案是关闭 IE 的所有实例,关闭 NUnit / VS 并重新开始,这非常有效。但是,我使用的是ConfirmDialogHandler 而不是AlertDialog Handler。
如果这没有帮助,您可能需要在启动浏览器实例之前尝试添加以下内容。
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.
我不熟悉 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
有一种方法可以在不等待的情况下执行此操作:
请参阅我的帖子:
需要一种方法来对 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
这有点不相关,但 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