UI 自动化和功能区控件 [英] UI Automation and Ribbon control
问题描述
我使用 UIAutomation API 对 WPF 应用程序进行自动化.一切都很顺利,直到我按下 Ribbon 控件.通过 Inspect.exe 可以轻松查看有关 Ribbon 及其子项的信息,但是在代码中我无法获取有关这些元素的信息.
I do automation for WPF application using UIAutomation API. Everything went fine until I hit the Ribbon control. I have no trouble to see information about Ribbon and its children through the Inspect.exe, but inside the code I cannot obtain the information about those elements.
换句话说,在这段代码中 aeElement 始终为空:
It other words, in this code aeElement is always null:
aeElement = aeForm.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "XXX"));
我尝试了 TreeScope.Descendants
和 TreeScope.Elements
.我尝试了 AutomationElement.ControlTypeProperty
和 AutomationElement.AutomationIdProperty
.我尝试了 TreeWalker
- 没有任何效果.
I tried TreeScope.Descendants
and TreeScope.Elements
.
I tried AutomationElement.ControlTypeProperty
and AutomationElement.AutomationIdProperty
.
I tried TreeWalker
– nothing worked.
想知道该问题是否有解决方案?预先非常感谢您.
Wondering if there is a solution for that issue? Thank you very much in advance.
推荐答案
最坏的情况是 root,对吗?然后尝试以下解决方案:
your worst case scenario is the root, correct? then try the following solution:
一个.从根开始搜索,然后深入到窗口、上下文等等
a. search from the root and then go deeper into the window, context, and so goes on
B.如果 a 不起作用,那么它一定是您的拼写.名称区分大小写.
b. if a didn't work, then it must be your spelling. the name is case sensitive.
c.你为什么不使用AutomationID?它是为此用途而创建的!
c. why aren't you using AutomationID? it was created for that use!
这篇关于UI 自动化和功能区控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!