【发布时间】:2017-08-10 22:30:53
【问题描述】:
我正在自动化 Windows 应用程序。我试图访问选项卡控件下的窗格元素(具有文本框、组合框控件),但无法访问。白色返回 null。
我尝试了其他技术,例如 UI 自动化 TreeWalker(原始视图、控制视图、内容视图),但没有任何帮助。
参考以下链接中的图片: https://dl.dropboxusercontent.com/u/68446125/Tab.png https://dl.dropboxusercontent.com/u/68446125/General%20Pane.png
如图 1 所示,选项卡控件被 White/UI 自动化正确检索,但子元素 General* Pane 没有返回,并且它的控件不可访问(参见图 2 突出显示),第一个可访问的子元素是“General * 选项卡项目”。
奇怪的是,这些控件可以在 Inspect.exe(在 windows SDK 中)中访问。我尝试了以下方法来检索控件,但 General* Pane 永远无法通过 White/UI 自动化访问。
var tab = Window.Get<Tab>(SearchCriteria.ByControlType(ControlType.Tab).AndByClassName("TwoPageControl")); // Tab control is retrieved properly
var pane = tab.GetElement(SearchCriteria.ByControlType(ControlType.Pane).AndByText("General*")); // this line returns NULL
var pane1 = revWindow.GetElement(SearchCriteria.ByControlType(ControlType.Pane).AndByText("General*")); // this line returns NULL
var pane2 = revWindow.Get<Panel>(SearchCriteria.ByControlType(ControlType.Pane).AndByText("General*"));// throws exception "Failed to get ControlType=pane,Name=General*,ControlType=pane"
也尝试过 Windows UI 自动化代码,但没有成功。
System.Windows.Automation.Condition cd1 = new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tab),
new PropertyCondition(AutomationElement.ClassNameProperty, "TwoPageControl"));
AutomationElement a = window.FindFirst(TreeScope.Descendants, cd1); // Tab control is returned properly here
TreeWalker rawViewWalker = TreeWalker.RawViewWalker;
AutomationElement cc = rawViewWalker.GetFirstChild(a); // General * Pane is not returned, instead General* Tab item is returned, though it's not the first child.
var cd = rawViewWalker.GetNextSibling(cc); // this returns next pane element available, not General * Pane.
请帮助我如何访问 General * Pane 及其在选项卡控制下的子项。非常感谢任何帮助。
【问题讨论】:
-
有什么方法适合你吗?
标签: ui-automation white-framework