我可以使用WatiN阅读JavaScript警告框吗?

Les*_*Les 11 watin

我想使用WatiN来验证JavaScript警告框中的错误消息.这可能吗?谢谢.

Dro*_*ror 13

请参阅Trev的博客此处.

using(IE ie = new IE("http://hostname/pagename.htm"))
{
    AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
    using (new UseDialogOnce(ie.DialogWatcher, alertDialogHandler ))
    {
        /*************************************
        * -- alert -- *
        * *
        * must use the "NoWait" to allow *
        * the code to goto the next line *
        * *
        *************************************/

        alertDialogHandler.WaitUntilExists();
        alertDialogHandler.OKButton.Click();
        ie.WaitForComplete();
    }
}
Run Code Online (Sandbox Code Playgroud)