提供属性Text时,UI Automation在选项卡控件中找不到tabPage

时间:2015-01-23 12:13:20

标签: winforms ui-automation microsoft-ui-automation

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

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

我找到了一个series of blogs 可能表明错误在于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");

0 个答案:

没有答案
相关问题