title: C# recursion to find automationElement in open dialog box
body: <p>I'm trying to browse to a file after i click the download button. But I though of writing a recursive function that finds controls in any window using AutomationElement library so hopefully i can find the nested controls in the open dialog window. This function is not working now. Please let me know where is the issue here or let me know if you have any suggestions.</p>
  
  <p>The problem is that It never gets to the else statement and never ends. So i don't think it finds the element at all. </p>
  
  <p>Here is the element highlighted that i'm trying to get using: </p>
  
  <p><a href="http://i.stack.imgur.com/ae21D.jpg" rel="nofollow">screenshot from inspect</a></p>
  
  <p>Thanks</p>
  
  <pre><code> private AutomationElement GetElement(AutomationElement element, Condition conditions, string className)
      {
          AutomationElement boo = null;
          foreach (AutomationElement c in element.FindAll(TreeScope.Subtree, Automation.ControlViewCondition))
          {
              var child = c;
              if (c.Current.ClassName.Contains(className) == false)
              {
                  GetElement(child, conditions, className);   
               }
              else
              {
                  boo = child.FindFirst(TreeScope.Descendants, conditions);
              }
          }
  
          return boo;
      }
  </code></pre>