asp.net watin:在asp.net中使用watin执行测试时出错?

时间:2011-12-29 11:39:40

标签: asp.net watin

我使用以下代码测试JavaScript简单验证 以下是我用于WatiN的代码。

[STAThread]
    static void Main(string[] args)
    {
        IE ie = new IE("http://localhost:2034/WebForm3.aspx");
        ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Maximize);
        var confirm = new ConfirmDialogHandler();
        ie.AddDialogHandler(confirm);
        ie.TextField("TextBox1").TypeText("Pa");
        ie.Button("Button2").ClickNoWait();
        //dialoghandler.WaitUntilExists(5);        
        confirm.OKButton.Click();
        var dialoghandler = new AlertDialogHandler();
        ie.AddDialogHandler(confirm);
        **dialoghandler.OKButton.Click();**//the error is could not find dialog does not exist.
        dialoghandler.WaitUntilExists(10);
    }

1 个答案:

答案 0 :(得分:0)

对于Dialogbox中的错误,请单击,您可以通过...解析

ConfirmDialogHandler handler = new ConfirmDialogHandler();
using (new UseDialogOnce(ie.DialogWatcher, handler))
{
   //trigger the event to popup dialogbox
   ie.Button("Button2").ClickNoWait();  //Copied from your code
   handler.WaitUntilExists();
   handler.OKButton.Click();
}