4

[Automation] TreeItems of WindowsFormsApplication with target framework .Net 4.5.2 running on WinServer2012 R2 cannot be captured

I've created a sample windows application project containing a TreeView with two nodes. Each of the two nodes has child nodes. Something like

-Node0

...Node2

...Node3

-Node1

...Node4

...Node5

...Node6

Using the following code, it seems the tree items cannot be captured properly resulting to nodes.Count == 1. I'm expecting Count == 2 (Node0 and Node1)

using System.Windows.Automation;

namespace Tester
{
   public class Class1
   {
      public void Test()
      {
         var desktop = AutomationElement.RootElement;

         var forms = desktop.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "MyForm"));

         var trees = forms[0].FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "treeView1"));

         var nodes = trees[0].FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem));

      }
   }
}

Note: I've been using FindAll() to recheck if only 1 instance is being captured.

Add Reference to:

  • UIAutomationClient (File Version: 4.0.30319.34211 built by: FX452RTMGDR)
  • UIAutomationTypes (File Version: 4.0.30319.34211 built by: FX452RTMGDR)

Some deductions.

1.

  • Server OS: Win2008ServerR2
  • WinFormsApp Target Framework: .Net 4.0
  • Result: OK

2.

  • Server OS: Win2008ServerR2
  • WinFormsApp Target Framework: .Net 4.5.2
  • Result: OK

3.

  • Server OS: Win2012ServerR2
  • WinFormsApp Target Framework: .Net 4.0
  • Result: OK

4.

  • Server OS: Win2012ServerR2
  • WinFormsApp Target Framework: .Net 4.5.2
  • Result: Not OK - nodes.Count == 1

5.

  • Server OS: Win2012ServerR2
  • WPF Target Framework: .Net 4.5.2
  • Result: OK

Thoughts?

Back2WorkMinion
  • 221
  • 1
  • 2
  • 8
  • What exactly is "Not OK" - do you get any exceptions, or simply empty results? My first thought would be to check if the referenced assemblies are actually located on the target machine. – Lars Kristensen Feb 26 '16 at 07:46
  • Not OK means nodes.Count == 1. As for the UI, it contains 2. Moreover, that only retrieved node does not contain at least Name property. The dlls are there and can be found in: C:\Program Files(x86)\Reference Asemblies\Microsoft\Framework\.NETFramework\v4.5.2 – Back2WorkMinion Feb 26 '16 at 08:09
  • I just created a simple WPF app with a treeview with the same structure as you described (2 parent nodes, with 2 and 3 children respectively), and tried your code. The number of nodes returned were 7. Are you sure the code is capturing the intended application / treeview? Could there be other applications open that also contain treeviews with a different number of nodes? – Lars Kristensen Feb 26 '16 at 08:37
  • Thanks for pointing out that WPF app. Yes it works in WPF, but not in our WindowsFormsApplication with target framework 4.5.2. Yep I am sure there are no other applications open containing those properties. Is it possible this issue only appears on WFA? – Back2WorkMinion Feb 26 '16 at 09:28
  • I just tried again with a WinForms app with the same treeview setup, and then I received `nodes.Count == 2`. I don't have access to a Windows2012 server to test further on, so I'm afraid I can't help anymore. – Lars Kristensen Feb 26 '16 at 09:52
  • Thanks Lars. Yes, we've found it as an isolated case in WinServer2012. It is working on Win7, and WinServer 2008. – Back2WorkMinion Feb 26 '16 at 09:55
  • @Back2WorkMinion did you find a solution to this? I'm hitting the same issue, works fine on 7 but not on Win2012R2... – JuChom Feb 14 '18 at 15:17

0 Answers0