【发布时间】:2013-09-09 14:16:05
【问题描述】:
我正在使用UIAutomation 操作一个旧程序。我遇到的问题涉及使用InvokePattern 按下按钮。
按下打开资源管理器窗口的按钮并获得窗口的AutomationElement 后,我获得了“打开”按钮的AutomationELement,实际上是SplitButton。我可以轻松找到该元素,但它以窗格控件而不是SplitButton 控件的形式出现。但是,如果我在查找 Button 元素之前插入断点并在 Debug 模式下手动单步执行代码,则“打开”按钮会被识别为 Button。
如果我在找到Button 元素后插入断点,则元素名称和AutomationID 是正确的,但ControlType 是窗格而不是按钮。获取资源管理器窗口后是否延迟都没关系,它仅在调试时有效。这很奇怪。
有问题的代码如下:
InvokePattern bPattern = (InvokePattern)button.GetCurrentPattern(InvokePattern.Pattern);
bPattern.Invoke();
for (int wait = 0; wait < 50; wait++)
{
if (explorerWindow != null)
break;
explorerWindow = reportWindow.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "Select Report"));
Thread.Sleep(200);
}
explorerOpenButton = explorerWindow.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "Open"));
【问题讨论】:
标签: c# .net winforms automation ui-automation