的UIElement返回空文本

问题描述 投票:0回答:1

我正在写一个需要监听应用程序的AutomationElement软件。这AutomationElementListBox内定义。当我使用inspect.exe来检查我如何能得到值,相应AutomationElement没有孩子。

下面是我使用的尝试获得ListItem的代码:

AutomationElement desktop = AutomationElement.FromHandle (tskBarHwndTest);
AutomationElement dataGrid1 = desktop.FindFirst (System.Windows.Automation.TreeScope.Descendants, new PropertyCondition (AutomationElement.AutomationIdProperty, "QueueListView"));
if (dataGrid1! = null)
{
    AutomationElementCollection lines1 = dataGrid1.FindAll (System.Windows.Automation.TreeScope.Descendants, new PropertyCondition (AutomationElement.ControlTypeProperty, ControlType.ListItem));
    GridPattern pattern = GetGridPattern (dataGrid1);
    AutomationElement tempElement = pattern.GetItem (0, 2)
}

Screenshot Inspect

c# ui-automation
1个回答
0
投票

我看到你正在寻找"QueueListView"但在inspect.exe截图我没有看到AutomationElement是有了这样的AutomationId桌面的后裔。

我会建议使用System.Windows.Automation.TreeScope.ChildrenTreeScope和步进一次一个元素。当使用Descendants这将是非常缓慢的找到任何东西,如果你的应用程序是不平凡的。

既然不能看到所有的值在检查它会是这个样子。

AutomationElement desktop = AutomationElement.RootElement;
AutomationElment mainWindow = desktop.FindFirst(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "<Your Main Window Name>");
//... add code here to get from main window to where your screen shot starts
AutomationElement panello1 = mainWindow.FindAll(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "pannello"))[2];
AutomationElement tabulazione = panello1.FindFirst(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "tabulazione"));
AutomationElement panello2 = tabulazione.FindFirst(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "panello"));
AutomationElement interazioniPersonali = panello2.FindFirst(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Interazioni personali"));
AutomationElement elenco = interazioniPersonali.FindFirst(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "elenco"));
AutomationElement voceDiElenco = interazioniPersonali.FindFirst(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "voce di elenco"));
AutomationElement numero = voceDiElenco.FindAll(System.Windows.Automation.TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "testo"))[2];
//... in if you expand the selected AutomationElement in your screenshot there should be a text element that contains the text you want to get

这绝对是可以提炼但是我可以在截图中看到这只是基础。

© www.soinside.com 2019 - 2024. All rights reserved.