Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watin - Handling Confirm Dialogs with ConfirmDialogHandler

Tags:

c#

asp.net

watin

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;
like image 887
Matt Roberts Avatar asked May 19 '09 13:05

Matt Roberts


3 Answers

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();
        }
like image 136
andreja Avatar answered Oct 23 '22 10:10

andreja


I had the same problem and tried many things but just overlooked one part i was calling .Click() and then just changed it to .ClickNoWait() and things sorted. Hope this helps

like image 2
MAK Avatar answered Oct 23 '22 09:10

MAK


I was facing the same issue and no matter what I do it was not working until I found a workaround which take time but work for me.

The default time to elapse for WaitUntilExists() is 30 secs so when using it in IE9 provide extended time limit as following.

handler.WaitUntilExists(40); // or whatever time suits you above 30

It certainly take time but it works.

like image 1
Jawad Hashim Avatar answered Oct 23 '22 10:10

Jawad Hashim