我正在编写需要拦截应用程序AutomationElement
的软件。该AutomationElement
在ListBox
中定义。当我使用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)
}
答案 0 :(得分:0)
我看到您正在寻找"QueueListView"
,但是在inspect.exe屏幕截图中,我没有看到AutomationElement
是台式机的后代,像这样的AutomationId
。
我建议您为System.Windows.Automation.TreeScope.Children
使用TreeScope
并一次步进一个元素。如果您的应用程序很简单,那么使用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
这绝对可以改进,但这只是基于我在屏幕快照中看到的内容。