c# - UIElement 返回空文本
问题描述
我正在编写需要拦截AutomationElement
应用程序的软件。这AutomationElement
是在 a 中定义的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)
}
解决方案
我看到您正在寻找,"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
这绝对可以改进,但这只是基于我在屏幕截图中看到的。
推荐阅读
- python - 如何跨子行和子列聚合熊猫数据透视表
- linear-programming - 使用 split 命令拆分字符串
- amazon-dynamodb - AWS Scan on DynamoDB 条件表达式选项
- laravel - Laravel 条带集成
- django - 如何在 django 网站中使用 ajax 添加评论?
- javascript - 汉堡菜单在屏幕 700px html/css/js 前端网络开发后不显示
- sql - 如何使用 psql 中的 row_number() 从表中删除重复项?
- sql - 通过替换内部查询改进 SQL 查询
- amazon-web-services - AWS EC2 现货实例可用性
- python - 我们可以删除引用循环对象并释放它的内存吗?