我已经尽可能地简化了这个问题,下面的代码可以剪切并粘贴到“test.linq”文件中并加载到 LinqPad 中。就目前而言,在 LinqPad 中运行此代码将显示它正在工作 - 目的是tabPage1
使用 UI 自动化框架找到带有 AutomationId 的窗格。
现在注释掉工作线并引入虚线。现在找不到标签页...唯一的区别是标签页是用Text
属性声明的。
我发现了一系列博客,这些博客可能表明错误出在一个自动化提供程序上,TabControl
但是已经反编译了TabControl
源代码,我看不出是这种情况,但是基础Control
实现了一个处理程序,WM_GETOBJECT
我真的不是确定这会导致什么。
有任何想法吗?
<Query Kind="Statements">
<Reference><RuntimeDirectory>\WPF\UIAutomationClient.dll</Reference>
<Reference><RuntimeDirectory>\wpf\UIAutomationProvider.dll</Reference>
<Reference><RuntimeDirectory>\wpf\UIAutomationTypes.dll</Reference>
<Reference><RuntimeDirectory>\Accessibility.dll</Reference>
<Reference><RuntimeDirectory>\wpf\WindowsBase.dll</Reference>
<Reference><RuntimeDirectory>\System.Windows.Forms.dll</Reference>
<Reference><RuntimeDirectory>\System.Security.dll</Reference>
<Reference><RuntimeDirectory>\System.Configuration.dll</Reference>
<Reference><RuntimeDirectory>\System.Deployment.dll</Reference>
<Reference><RuntimeDirectory>\System.Runtime.Serialization.Formatters.Soap.dll</Reference>
<Namespace>System.Windows.Automation</Namespace>
<Namespace>System.Windows.Forms</Namespace>
</Query>
var tabControl = new TabControl();
tabControl.Name = "tabControl";
// Broken
//tabControl.TabPages.Add(new TabPage() { Name = "tabPage1", Text = "First Tab" });
// Working
tabControl.TabPages.Add(new TabPage() { Name = "tabPage1" });
var form = new Form() { Name = "Form1" };
form.Controls.Add(tabControl);
form.Show();
var desktop = AutomationElement.RootElement;
var frmTest = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "Form1"));
var tabPage1 = frmTest.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "tabPage1"));
tabPage1.Dump("tabPage1");