title: Coded UI discovering controls
body: <p>I have a ui coded ui test in visual studio 2010. 
  I want to write a code which will:</p>
  
  <ol>
  <li>Discover all the controls on a window <strong>and child windows</strong> which are button, grid, label</li>
  <li>write a uimap with the id which is the name of the control in the code.</li>
  </ol>
  
  <p>For starting it, I've write the following:</p>
  
  <pre><code>public void CodedUITestMethod1()
  {    
     string uiTestFileName = @"D:\dev11\ConsoleApplication1\TestProject1\UIMap.uitest";
  
     UITest uiTest = UITest.Create(uiTestFileName);
  
     Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap newMap = new Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap(); 
     newMap.Id = "UIMap"; 
     uiTest.Maps.Add(newMap);
  
     GetAllChildren(BrowserWindow.Launch(new Uri("http://bing.com")), uiTest.Maps[0];);
     uiTest.Save(uiTestFileName);    
  }
  
  private void GetAllChildren(UITestControl uiTestControl, Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap map)
  {
     foreach (UITestControl child in uiTestControl.GetChildren())
     {
         map.AddUIObject((IUITechnologyElement)child.GetProperty(UITestControl.PropertyNames.UITechnologyElement));
  
         GetAllChildren(child, map);    
      }    
  }
  </code></pre>
  
  <p>But it insert into the recursive loop and doesn't end it.</p>
  
  <p>Can anyone help me?</p>