Search code examples
watin

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.


Solution

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