Windows UI Automation API not finding child elements when run on server
===

I'm using the [Microsoft UI Automation API][1] from within NUnit 2.5.10 tests to perform automated UI testing for a WPF application.

There some cases where running the tests on my development machine is able to locate certain UI elements, but when the same script is run against the same binaries on our build agent machine, it is unable to locate those elements.

I can't find any reason why the agent machine behaves differently. I suspect it has something to do with UIAccess flags or UAC, but haven't come across anything specific.

**Can anyone provide some guidance as to why the build agent would have different behavior, or how to fix the agent to see the same elements as my other machines?**

For example, I have a comboBox, which has about a dozen options in it.  Using the "Inspect Objects" tool from the Win7 SDK, I can see that each option has a child element which has the actual displayed text.  So in my test code, I do something like this:


    // get the child elements
    var options = comboBoxElement.FindAll(TreeScope.Children, (System.Windows.Automation.Condition) new PropertyCondition(AutomationElement.IsControlElementProperty, (object) true));
    
    foreach (AutomationElement child in viewOptions)
    {
        var subControls = child.GetChildren();
        Console.WriteLine("Child: {0} w/ {1} children", child.Current.Name,  subControls.Count);
        foreach (AutomationElement subControl in subControls)
            Console.WriteLine("SubControl: {0}", subControl.Current.Name);
    }


On my dev machine, I get these results:

    Child: My.BoundObject.ClassName w/ 1 children
    SubControl: Displayed Text for first item
    Child: My.BoundObject.ClassName w/ 1 children
    SubControl: Displayed Text for second item
    Child: My.BoundObject.ClassName w/ 1 children
    SubControl: Displayed Text for third item

But on the server, I get this:

    Child: My.BoundObject.ClassName w/ 0 children
    Child: My.BoundObject.ClassName w/ 0 children
    Child: My.BoundObject.ClassName w/ 0 children

In both cases, Inspect Objects shows the child objects.
![Inspect Options screenshot][2]

Both the build agent and my local machine are running Windows 7 SP1 with .Net 4.  In both cases, I am running the nunit-console.exe to kick off the tests.  I'm copying the entire environment between the machines, so not only is it the same version of nunit and my app's binaries, it's exactly the same files, configs, libraries, etc.  The nunit-console is running as an Administrator user.


  [1]: http://msdn.microsoft.com/en-us/library/ms747327
  [2]: http://i.stack.imgur.com/DqOzU.png

