我正在使用UIAutomation
. 我遇到的问题涉及使用InvokePattern
.
在按下一个打开资源管理器窗口的按钮并获得窗口的按钮后AutomationElement
,我得到AutomationELement
一个“打开”按钮,实际上是一个SplitButton
. 我可以很容易地找到该元素,但它以窗格控件而不是SplitButton
控件的形式出现。但是,如果我在查找 Button 元素之前插入断点并在调试模式下手动单步执行代码,则“打开”按钮会被识别为 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"));