Steve Johnstone
Steve Johnstone

Reputation: 576

Handling Inline JavaScript Dialogues with WatiN

The site that we're currently writing tests for has some JavaScript confirm and alert dialogues that happen after the page has refreshed, and are written in inline JavaScript. For example:

<script>
if (confirm('Outcome has been saved. Click OK to create a followup appointment, or click Cancel to return to appointment outcome details.')) {
   pbFup.click();
}
</script>

Our test scripts don't seem to be able to handle this, and I can't figure out if we're doing something wrong, or if it's failing because WatiN can't handle the inline JavaScript. One of our tests looks like this:

var confirmDialogHandler = new ConfirmDialogHandler();
using (new UseDialogOnce(IEInstance.DialogWatcher, ConfirmDialogHandler))
{
    frame.Button(Find.ByName("cbnSave")).Click();
    // The page should reload here.
    confirmDialogHandler.WaitUntilExists();
    confirmDialogHandler.OKButton.Click();
}
IEInstance.WaitForComplete();

Upvotes: 2

Views: 413

Answers (1)

Piriya
Piriya

Reputation: 21

I used AlertDialogHandler() and it's working for me now.

Upvotes: 1

Related Questions