title: How to traverse all the child elements of a program
body: <p>I want to build a tree of UI elements that are present in an application. I am trying to use Microsoft UI Automation. I can get access to the desktop by accessing AutomationElement.RootElement but I am not sure how to access the application that is running on the desktop.</p>
  
  <p>The main goal is to build a UI tree of the target application already running on the desktop. I do not have access to the code of the target application. </p>
  
  <p>When I try to run         </p>
  
  <pre><code>foreach (var item in AutomationElement.RootElement.CachedChildren)
          {
              Console.WriteLine(item.ToString());
          }
  </code></pre>
  
  <p>It gives me Fatal error: Can not get the property or element that is not cached.</p>
  
  <p>Please suggest what is the best way to tackle this problem.</p>