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 }
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.Find("//Window[@caption='My Window']", new FindOptions(false)) if (mainWindow != null){ mainWindow.CloseSynchron() }