2011-12-29 70 views
0

我已经使用下面的代码来测试JavaScript简单验证。
下面是我用于WatiN的代码。asp.net watin:执行测试时使用watin在asp.net中发生错误?

[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); 
    } 

回答

0

对于对话框单击确定错误,可以通过解决...

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