0

我已经尽可能地简化了这个问题,下面的代码可以剪切并粘贴到“test.linq”文件中并加载到 LinqPad 中。就目前而言,在 LinqPad 中运行此代码将显示它正在工作 - 目的是tabPage1使用 UI 自动化框架找到带有 AutomationId 的窗格。

现在注释掉工作线并引入虚线。现在找不到标签页...唯一的区别是标签页是用Text属性声明的。

我发现了一系列博客,这些博客可能表明错误出在一个自动化提供程序上,TabControl但是已经反编译了TabControl源代码,我看不出是这种情况,但是基础Control实现了一个处理程序,WM_GETOBJECT我真的不是确定这会导致什么。

有任何想法吗?

<Query Kind="Statements">
  <Reference>&lt;RuntimeDirectory&gt;\WPF\UIAutomationClient.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\wpf\UIAutomationProvider.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\wpf\UIAutomationTypes.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\Accessibility.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\wpf\WindowsBase.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\System.Windows.Forms.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\System.Security.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\System.Configuration.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\System.Deployment.dll</Reference>
  <Reference>&lt;RuntimeDirectory&gt;\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");
4

0 回答 0