The dialog watcher class is used to handle javascript and other dialogs. The IE instance can have a dialog watcher which can have dialog handlers assigned to it to assist in processing pop up dialogs.
Example of Usage
This is a rework of the TestAddDialogHander2 test that was introduced earlier:
''' <summary> ''' Ensure that an alert dialog will be handled and ''' closed properly. ''' </summary> ''' <remarks> ''' currentURL is a Private Const = ''' "http://localhost:3587/popup.html" ''' HelloButton is a Private Const = "hello" ''' </remarks> <Test()> _ Public Sub TestAddDialogHandler2Plus() Using ie As IE = New IE(currentURL) Dim myHandler As New AlertAndConfirmDialogHandler Dim myWatcher As New DialogWatcher(ie.ProcessID) myWatcher.Add(myHandler) ie.Button(HelloButton).ClickNoWait() Assert.IsTrue(myWatcher.Count > 0, "There should be a hello dialog open at this point.") ie.WaitForComplete() End Using End Sub
The dialog watcher is created from the IE instance and is therefore already assigned to it. A handler is added to process the javascript popup and the button is clicked to display the dialog.
Another way of using the dialog watcher is presented next:
''' <summary> ''' Ensure that an alert dialog will be handled and ''' closed properly. ''' </summary> ''' <remarks> ''' currentURL is a Private Const = ''' "http://localhost:3587/popup.html" ''' HelloButton is a Private Const = "hello" ''' </remarks> <Test()> _ Public Sub TestAddDialogHandler2Plus2() Using ie As IE = New IE(currentURL) Dim myHandler As New AlertAndConfirmDialogHandler Dim myWatcher As DialogWatcher myWatcher = ie.DialogWatcher myWatcher.Add(myHandler) ie.Button(HelloButton).ClickNoWait() Assert.IsTrue(myWatcher.Count > 0, "There should be a hello dialog open at this point.") ie.WaitForComplete() End Using End Sub
Here the dialog watcher is not created from the IE instance, so it must be specifically assigned.
Contents: Table of Contents Previous Page: WatiN API Reference - ContainsText Next Page: WatiN API Reference - Dispose