Conditional Dialog Handling

I would like to conditionally handle a dialog. If it appears, I'd like to handle it normally. If it doesn't, I'd like to continue with test execution.

Solution

This is possible with a coded solution. The action that potentially triggers the dialog must be included in the code.

ActiveBrowser.NavigateTo("http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert");

//Create the dialog and add it to the monitor
AlertDialog ad = AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK);
Manager.DialogMonitor.AddDialog(ad);

//Trigger the dialog
//Comment out the following line to see the code work when the dialog isn't fired
ActiveBrowser.Frames["view"].Find.ByExpression<HtmlInputButton>("value=Show alert box", "tagname=input").Click();

//If the dialog fires, it's handled
//If not, the exception is silently disposed
try
{
    ad.WaitUntilHandled(2000);
}
catch (TimeoutException)
{
}

//Remove the dialog from the monitor
Manager.DialogMonitor.RemoveDialog(ad);

ActiveBrowser.NavigateTo("http://www.bing.com");
ActiveBrowser.NavigateTo("http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert")


Dim ad As AlertDialog = AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK)
Manager.DialogMonitor.AddDialog(ad)


ActiveBrowser.Frames("view").Find.ByExpression(Of HtmlInputButton)("value=Show alert box", "tagname=input").Click()


Try
    ad.WaitUntilHandled(2000)
Catch generatedExceptionName As TimeoutException
End Try


Manager.DialogMonitor.RemoveDialog(ad)

ActiveBrowser.NavigateTo("http://www.bing.com")