[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?