title: Can't determine if a certain UITestControl exists in my web app
body: <p>I'm currently trying to help automate some coded UI tests using C# for a web application.  A frequent problem I'm encountering is that it can be extremely difficult to determine if a <code>UITestControl</code> object exists on the page or not.  Unfortunately, Microsoft's documentation on their MSDN website for anything regarding coded UI tests is practically non-existant (<a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.uitestcontrol.aspx">see here their page for <code>UITestControl</code></a>).  </p>
  
  <p><strong>Basically what I'm asking is:</strong></p>
  
  <ul>
  <li>What is the best way to determine if a <code>UITestControl</code> exists on the page or not?</li>
  <li>How does the <code>UITestControl.Exists</code> property work?</li>
  <li>What does the <code>UITestControl.Find()</code> method do?</li>
  <li>How does the <code>UITestControl.TryFind()</code> method work?</li>
  </ul>
  
  <p><strong>How I've tried to handle it:</strong></p>
  
  <p>As I mentioned earlier, the documentation on all of these classes and methods is mostly blank.  The most you can get to describe any of the methods and properties is a 1 line description in Intellisense, so I've been experimenting with the methods that are listed.</p>
  
  <p>First I tried checking if the <code>UITestControl.Exists</code> property was true, but over time and consulting others' experience with it, it became apparent that it always returns true, even if the browser isn't open.  Since the option that seemed most obvious wasn't working, I tried using the <code>UITestControl.Find()</code> method, but since it takes no arguments and returns nothing I couldn't figure out what it did.  I tried using the <code>UITestControl.TryFind()</code> method, and occasionally it worked, but I found that it only seemed to return false when I wasn't on the correct page; it always returned true otherwise.  Clearly I had no idea how it worked, and shouldn't use it as a test.</p>
  
  <p>I figured if I couldn't get the provided methods to do their job, I'd have to try to make my own tools.  I most recently tried using <code>Mouse.Hover(UITestControl)</code> in a try/catch block to determine if the control exists like so:</p>
  
  <pre><code>public bool DoesExist(UITestControl control){
     if(control == null)
        return false;
  
     try{ Mouse.Hover(control); }
     catch (UITestException)
     {
        return false;
     }
  
     return true;
  }
  </code></pre>
  
  <p>It works sometimes, but in certain situations it seems to return false positives for reasons I don't understand.  I'm still flying blind, and I'm nearly out of ideas.</p>
  
  <p>I am using Visual Studio 2012, and Microsoft .NET Framework version 4.5.50709.</p>