user56737
user56737

Reputation:

Can I read JavaScript alert box with WatiN?

I want to use WatiN to verify the error message in a JavaScript alert box. Is this possible? Thanks.

Upvotes: 11

Views: 3589

Answers (1)

Dror
Dror

Reputation: 7303

see Trev's Blog and here as well.

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

Upvotes: 12

Related Questions