我正在尝试单击 javascript 警报窗口的“确定”按钮。但是,该方法AddDialogHandler
会抛出未设置为对象实例的对象引用。我究竟做错了什么?
// Class
IE browser;
button_click()
{
var thread = new Thread(() =>
{
WatiN.Core.Settings.AutoStartDialogWatcher = false;
browser = new IE(webBrowser1.ActiveXInstance);
ReturnDialogHandler myHandler = new ReturnDialogHandler();
browser.AddDialogHandler(myHandler); // This line throws exception
browser.Button(Find.ById("alertButton")).ClickNoWait();
myHandler.WaitUntilExists();
myHandler.OKButton.Click();
browser.WaitForComplete();
});
thread.Name = "KillAlertWindowAsync";
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}