c# – Watin – 使用ConfirmDialogHandler处理确认对话框

栏目: ASP.NET · 发布时间: 7年前

内容简介:http://stackoverflow.com/questions/882683/watin-handling-confirm-dialogs-with-confirmdialoghandler

使用Watin,我试图处理一个确认对话框,并告诉Watin按“OK”.这在互联网上有很好的记录 – 您使用ConfirmDialogHandler和UseDialogOnce方法..除了它不适用于我.我收到以下错误:

WatiN.Core.Exceptions.WatiNException:对话框在5秒钟内不可用

我正在使用watin 2.0 beta atm,但是我以前使用的是早期版本的1.X,它具有相同的问题.在运行64位Vista的同事机器上进行测试,我运行的是64位Windows 7.

代码如下所示:

using (IE ie = new IE("http://localhost/TestApp/TestConfirmPage.asp"))
        {
            var approveConfirmDialog = new ConfirmDialogHandler();

            using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
            {
                ie.Button(Find.ByName("btn")).ClickNoWait();
                approveConfirmDialog.WaitUntilExists(5);
                approveConfirmDialog.OKButton.Click();
            }
            ie.WaitForComplete();
        }

ASP页面非常简单,它包含一个强制确认的按钮,如下所示:

<input type="button" name="btn" id="btn" value="Click me" onclick="ConfirmApp()"  />

而ConfirmApp已经被剥离了测试,所以现在它包含的是:

bOK = confirm("You clicked a popup. Did you mean to?");
 return bOK;

代码对我来说很好,我认为它应该有效.唯一的想法是做不同的是把等待完成里面使用对话框块.不知道为什么,但在我这样做之前,我也有一些问题,有时它有时它不工作.而在等待直到存在的时候我不会使用时间限制.但是你可能已经尝试过了.

例如:

using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
        {
            ie.Button(Find.ByName("btn")).ClickNoWait();
            approveConfirmDialog.WaitUntilExists();
            approveConfirmDialog.OKButton.Click();
            ie.WaitForComplete();
        }

http://stackoverflow.com/questions/882683/watin-handling-confirm-dialogs-with-confirmdialoghandler


以上所述就是小编给大家介绍的《c# – Watin – 使用ConfirmDialogHandler处理确认对话框》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

High Performance Python

High Performance Python

Andrew Lewis / O'Reilly Media, Inc. / 2010-09-15 / USD 34.99

Chapter 1. Introduction Section 1.1. The High Performance Buzz-word Chapter 2. The Theory of Computation Section 2.1. Introduction Section 2.2. Problems Section 2.3. Models of Computati......一起来看看 《High Performance Python》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具