Using Locators to Check if an Object Exists

You can use the Exists method to determine if an object exists in the application under test.

The following code checks if a hyperlink with the text Log out exists on a Web page:

If (browserWindow.Exists( "//a[@textContents='Log out']" )) Then
  ' do something
End If

Using the Find method

You can use the Find method and the FindOptions method to check if an object, which you want to use later, exists.

The following code searches for a window and closes the window if the window is found:

Dim mainWindow As Window
mainWindow = _desktop.Find("//Window[@caption='My Window']", New FindOptions(False))
If (mainWindow IsNot Nothing) Then
End If