Reputation: 26877
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;
Upvotes: 15
Views: 8419
Reputation: 33
Just spent a couple of hours with variations on the dialog watcher solution. Nothing worked for me in IE9.
I ended up with a one-liner that works for me, hope it helps somebody else! This approach completely avoids trying to deal with the dialog by using user key presses instead.
SendKeys.SendWait("{ENTER}");
nb: using System.Windows.Forms
Upvotes: 0
Reputation: 29
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
Upvotes: 2
Reputation: 31
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.
Upvotes: 1
Reputation: 487
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();
}
Upvotes: 11