How to detect Javascript toast notifications in WatiN?

I have what I think is a fairly common scenario that I am trying to work with.

I have a site that accepts input via two different text boxes. If the input is incorrect or invalid, I get a Javascript toast notification.

I won't always get one, but I must in case (as I said before) distort the data or when a search result cannot be found.

How can I detect this in WatiN?

A quick google search returned results showing how they can be clicked, but I'm curious if I can detect when I get it?

In case anyone is wondering, I am using WatiN to take some screenshots for me, not to test the integration :)

Thanks in advance!

Yang

+2


a source to share


1 answer


Here's what I came up with.

I read this question several times before coming up with an obvious solution.

Is it possible to read a JavaScript alert box using WatiN?



This is the code I came up with. Although it does delay 3 seconds, if no warning occurs, it works fine for my scenario.

Hope someone else finds this helpful.

frame.Button(Find.ByName("go")).ClickNoWait();

System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();

while (stopwatch.Elapsed.TotalMilliseconds < 3000d)
{
    if (alertDialogHandler.Exists())
    {
        // Do whatever I want to do when there is an alert box.
        alertDialogHandler.OKButton.Click();
        break;
    }
}

      

+2


a source







All Articles