views:

1234

answers:

2

Hi,

Using Watin, I'm trying to handle a confirm dialog box and tell watin to press "OK". This is reasoanbly well documented on the internet - you use a ConfirmDialogHandler and the "UseDialogOnce" method.. Except it isn't working for me. I get the following error:

WatiN.Core.Exceptions.WatiNException: Dialog not available within 5 seconds

I'm using the watin 2.0 beta atm, but I was previously using an earlier version of 1.X which had the same issue. Tested on a colleagues machine running 64 bit Vista, I'm running 64 bit Windows 7.

The code looks like this:

        using (IE ie = new IE("http://localhost/TestApp/TestConfirmPage.asp"))
        {
            var approveConfirmDialog = new ConfirmDialogHandler();

            using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
            {
                ie.Button(Find.ByName("btn")).ClickNoWait();
                approveConfirmDialog.WaitUntilExists(5);
                approveConfirmDialog.OKButton.Click();
            }
            ie.WaitForComplete();
        }

The ASP page is very simple, it consists of a button that forces a confirm, like this:

<input type="button" name="btn" id="btn" value="Click me" onclick="ConfirmApp()"  />

And ConfirmApp has been stripped down for testing so that now all it contains is:

 bOK = confirm("You clicked a popup. Did you mean to?");
 return bOK;
A: 

The code looks fine to me, and I think it should work. The only think I did differently it was to put Wait for Complete inside using Dialog block. Don't know why but before I did that I also have some issues, sometimes it works sometimes it doesn't. And I don't use time limitation at Wait until exists. But you probably already tried that one.

For example:

using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
        {
            ie.Button(Find.ByName("btn")).ClickNoWait();
            approveConfirmDialog.WaitUntilExists();
            approveConfirmDialog.OKButton.Click();
            ie.WaitForComplete();
        }
andreja
Using a combination of code changes like this and a refresh of the DLLs sorted it.
Matt Roberts
A: 

Hi mattwoberts Did you manage to sort out your problem with WatiN not handling confirm dialogs? I am having a similar problem its not working on Vista 32 while I have tested it on another maching running Windows 7 and it runs fine. I will appreciate any help in this regards.

warm regards, Bilal.

Bilal
Hi Bilal. I did get it working but I can't remember exactly what I did - I have a feeling I updated a bunch of libraries like the latest NUnit and Watin, and then everything started working for me...
Matt Roberts