Visual Basic
<TestMethod(), _
Description("How to access and handle IE's modal dialogs")> _
Public Sub IEModalDialogsSupport()
Manager.LaunchNewBrowser(BrowserType.InternetExplorer, True)
ActiveBrowser.NavigateTo(TESTPAGE2)
' Open the popup using mouse click so it doesn't hang execution.
Find.ByAttributes(Of HtmlInputButton)("type=button").MouseClick()
' ** Special IE Code. Given that IE Modal Dialog is an IE specific feature.
If (ActiveBrowser.BrowserType = BrowserType.InternetExplorer) Then
Dim ieActions As ArtOfTest.WebAii.BrowserSpecialized.InternetExplorer.InternetExplorerActions = CType(ActiveBrowser.Actions, ArtOfTest.WebAii.BrowserSpecialized.InternetExplorer.InternetExplorerActions)
' Connect the dialog
ieActions.ConnectIEDialog("Modal1 -- Webpage Dialog", 300)
Manager.WaitForNewBrowserConnect("dialog.html", True, 10000)
Assert.IsTrue(ActiveBrowser.IsIEDialog)
' The ActiveBrowser instance is now the dialog instance. Do what ever you want with the dialog
ActiveBrowser.Find.ByTagIndex(Of HtmlContainerControl)("H1", 0).BaseElement.SetValue(Of String)("style.backgroundColor", "red")
' Once done, make sure to close the dialog.
' Even if the dialog is closed due to a button click within the dialog, you still need this line
' at this point to revert the ActiveBrowser instance to the main instance. We are searching for a
' good approach to make this automatic.
ActiveBrowser.Close()
End If
Assert.IsFalse(ActiveBrowser.IsIEDialog)
' The ActiveBrowser is back to the main browser window.
End Sub