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']" )) {
  // do something
}

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:

Window mainWindow = _desktop.<Window>find("//Window[@caption='My Window']", New FindOptions(False));
if (mainWindow){
  mainWindow.closeSynchron();
}