AutomationElement 使用 Inspect.exe 显示,但在使用 UIAutomationCore.dll 或 System.Windows.Automation 时不显示 [英] AutomationElement shows up using Inspect.exe but does show not up when using UIAutomationCore.dll or System.Windows.Automation

查看:64
本文介绍了AutomationElement 使用 Inspect.exe 显示,但在使用 UIAutomationCore.dll 或 System.Windows.Automation 时不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL;DR:我做错了什么导致工作区窗格显示在检查对象中但没有显示在我的自定义代码中?

<小时>

我正在尝试为 3rd 方程序编写一些 UI 自动化.我正在使用

PropertyCondition parentFileCond = new PropertyCondition(AutomationElement.ProcessIdProperty, 5872);PropertyCondition workspaceCond= new PropertyCondition(AutomationElement.NameProperty, "Workspace");var walker = new TreeWalker(workspaceCond);var parentElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, parentFileCond);var workspaceElement = walker.Normalize(parentElement);

但是对于 workspaceElement

也会返回 null

最后,无奈之下,我从Inspect中尝试了NativeWindowHandle"的当前值,并开始从根节点开始行走.

PropertyCondition workspaceCond = new PropertyCondition(AutomationElement.NativeWindowHandleProperty, 0x110906);var walker = new TreeWalker(workspaceCond);var workspaceElement = walker.Normalize(AutomationElement.RootElement);

Workspace 元素 STILL 为空.

<小时>

找到结果

我终于让 Workspace 出现了,但我不得不执行

PropertyCondition workspaceCond = new PropertyCondition(AutomationElement.NativeWindowHandleProperty, 0x110906);var test = AutomationElement.RootElement.FindFirst(TreeScope.Subtree, workspaceCond);

而且运行需要很长时间.

旧屏幕截图

这是 Inspect.exe 中显示树视图的屏幕截图.

这里是程序主窗口的属性.

如何找到:从树中选择...运行时 ID:[42.2557552]"边界矩形:{l:75 t:1 r:1311 b:1003}进程编号:8160控制类型:UIA_WindowControlTypeId (0xC370)本地化控件类型:窗口"名称:《已编辑》访问键:"HasKeyboardFocus:假IsKeyboardFocusable: 真已启用:真类名:C:Program Files (x86)RedactedProgramFiles7RedactedClientFolder"帮助文本:"IsPassword:假本机窗口句柄:0x270670IsOffscreen: 假框架 ID:Win32"ProviderDescription: "[pid:4000,hwnd:0x270670 Main:Nested [pid:8160,hwnd:0x270670 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore).dll)];非客户端:Microsoft:非客户端代理(非托管:uiautomationcore.dll);Hwnd(父链接):Microsoft:HWND 代理(非托管:uiautomationcore.dll)]"Window.CanMaximize: 真Window.CanMinimize: 真Window.WindowVisualState: 正常 (0)Window.WindowInteractionState: ReadyForUserInteraction (2)Window.IsModal: 假Window.IsTopmost:假Transform.CanMove: 真Transform.CanResize: 真Transform.CanRotate: 假LegacyIAccessible.ChildId: 0LegacyIAccessible.DefaultAction: ""LegacyIAccessible.Description: ""LegacyIAccessible.Help: ""LegacyIAccessible.KeyboardShortcut: ""LegacyIAccessible.Name:已编辑"LegacyIAccessible.Role: 客户端 (0xA)LegacyIAccessible.State:可聚焦(0x100000)LegacyIAccessible.Value: ""IsDockPatternAvailable: 假IsExpandCollapsePatternAvailable: falseIsGridItemPatternAvailable: falseIsGridPatternAvailable: 假IsInvokePatternAvailable: 假IsLegacyIAccessiblePatternAvailable: 真IsMultipleViewPatternAvailable: falseIsRangeValuePatternAvailable: 假IsScrollPatternAvailable: 假IsScrollItemPatternAvailable: falseIsSelectionItemPatternAvailable: falseIsSelectionPatternAvailable: falseIsTablePatternAvailable: 假IsTableItemPatternAvailable: falseIsTextPatternAvailable: 假IsTogglePatternAvailable: 假IsTransformPatternAvailable: 真IsValuePatternAvailable: 假IsWindowPatternAvailable: 真IsItemContainerPatternAvailable: falseIsVirtualizedItemPatternAvailable: falseIsSynchronizedInputPatternAvailable: falseFirstChild:工作区"窗格LastChild:应用程序"菜单栏Next: Inspect (HWND: 0x01700F06)"窗口上一篇:沙盒控制台(调试)-Microsoft Visual Studio(管理员)"窗口其他道具:对象没有附加属性子项:工作区"窗格(空)标题栏应用程序"菜单栏祖先:桌面"窗格[无父母]

这是问题工作区"窗格的属性.

如何找到:从树中选择...运行时 ID:[42.34146524]"边界矩形:{l:83 t:51 r:1303 b:995}进程编号:8160控制类型:UIA_PaneControlTypeId (0xC371)LocalizedControlType:窗格"名称:工作区"访问键:"HasKeyboardFocus:假IsKeyboardFocusable: 真已启用:真类名:MDIClient"帮助文本:"IsPassword:假本机窗口句柄:0x20908DCIsOffscreen: 假框架 ID:Win32"ProviderDescription: "[pid:4000,hwnd:0x20908DC Main:Nested [pid:8160,hwnd:0x20908DC Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore).dll)]; Hwnd(父链接):Microsoft:HWND 代理(非托管:uiautomationcore.dll)]"LegacyIAccessible.ChildId: 0LegacyIAccessible.DefaultAction: ""LegacyIAccessible.Description: ""LegacyIAccessible.Help: ""LegacyIAccessible.KeyboardShortcut: ""LegacyIAccessible.Name: "工作区"LegacyIAccessible.Role: 客户端 (0xA)LegacyIAccessible.State:可聚焦(0x100000)LegacyIAccessible.Value: ""IsDockPatternAvailable: 假IsExpandCollapsePatternAvailable: falseIsGridItemPatternAvailable: falseIsGridPatternAvailable: 假IsInvokePatternAvailable: 假IsLegacyIAccessiblePatternAvailable: 真IsMultipleViewPatternAvailable: falseIsRangeValuePatternAvailable: 假IsScrollPatternAvailable: 假IsScrollItemPatternAvailable: falseIsSelectionItemPatternAvailable: falseIsSelectionPatternAvailable: falseIsTablePatternAvailable: 假IsTableItemPatternAvailable: falseIsTextPatternAvailable: 假IsTogglePatternAvailable: 假IsTransformPatternAvailable: 假IsValuePatternAvailable: 假IsWindowPatternAvailable: 假IsItemContainerPatternAvailable: falseIsVirtualizedItemPatternAvailable: falseIsSynchronizedInputPatternAvailable: falseFirstChild:Untitled3"窗口LastChild: "Letters (32638 of 32638):" 窗口下一个:(空)标题栏上一篇:[空]其他道具:对象没有附加属性儿童:Untitled3"窗口信件(32638 中的 32638):"窗口祖先:编辑"窗口桌面"窗格[无父母]

这是工作"文档窗口的属性.

如何找到:从树中选择...运行时 ID:[42.9505096]"边界矩形:{l:85 t:53 r:651 b:491}进程编号:8160控制类型:UIA_WindowControlTypeId (0xC370)本地化控件类型:窗口"名称:《无题3》访问键:"HasKeyboardFocus:假IsKeyboardFocusable: 真已启用:真自动化 ID:10"类名:ProToolsSubMDIWndClass"帮助文本:"IsPassword:假本机窗口句柄:0x910948IsOffscreen: 假框架 ID:Win32"ProviderDescription: "[pid:4000,hwnd:0x910948 Main:Nested [pid:8160,hwnd:0x910948 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore).dll)];非客户端:Microsoft:非客户端代理(非托管:uiautomationcore.dll);Hwnd(父链接):Microsoft:HWND 代理(非托管:uiautomationcore.dll)]"Window.CanMaximize: 真Window.CanMinimize: 真Window.WindowVisualState: 正常 (0)Window.WindowInteractionState: ReadyForUserInteraction (2)Window.IsModal: 假Window.IsTopmost:假Transform.CanMove: 真Transform.CanResize: 真Transform.CanRotate: 假LegacyIAccessible.ChildId: 0LegacyIAccessible.DefaultAction: ""LegacyIAccessible.Description: ""LegacyIAccessible.Help: ""LegacyIAccessible.KeyboardShortcut: ""LegacyIAccessible.Name: "Untitled3"LegacyIAccessible.Role: 客户端 (0xA)LegacyIAccessible.State:可聚焦(0x100000)LegacyIAccessible.Value: ""IsDockPatternAvailable: 假IsExpandCollapsePatternAvailable: falseIsGridItemPatternAvailable: falseIsGridPatternAvailable: 假IsInvokePatternAvailable: 假IsLegacyIAccessiblePatternAvailable: 真IsMultipleViewPatternAvailable: falseIsRangeValuePatternAvailable: 假IsScrollPatternAvailable: 假IsScrollItemPatternAvailable: falseIsSelectionItemPatternAvailable: falseIsSelectionPatternAvailable: falseIsTablePatternAvailable: 假IsTableItemPatternAvailable: falseIsTextPatternAvailable: 假IsTogglePatternAvailable: 假IsTransformPatternAvailable: 真IsValuePatternAvailable: 假IsWindowPatternAvailable: 真IsItemContainerPatternAvailable: falseIsVirtualizedItemPatternAvailable: falseIsSynchronizedInputPatternAvailable: falseFirstChild:"拇指LastChild: (null) 标题栏下一篇:信函(32638 中的 32638):"窗口上一篇:[空]其他道具:对象没有附加属性儿童:"拇指(空)标题栏祖先:工作区"窗格编辑"窗口桌面"窗格[无父母]

解决方案

非常好的问题.根据您记录的问题,很明显您的条件是:

PropertyCondition workspaceCond = new PropertyCondition(AutomationElement.NameProperty、工作区"、PropertyConditionFlags.IgnoreCase);

... 评估失败.为什么?

答案是如何评估您的条件.查看您的元素树,我们注意到 Workspace 的此属性:

IsWindowPatternAvailable: false

对于主窗口和Untitled3:

IsWindowPatternAvailable: true

来自 MSDN:

<块引用>

UIA_IsWindowPatternAvailablePropertyId 30044

标识 IsWindowPatternAvailable 属性,该属性指示 Window 控件模式是否可用于自动化元素.如果 TRUE,客户端可以检索 IUIAutomationWindowPattern 来自元素的接口.

我们找到了一个repro 在此线程中,这意味着与您当前遇到的故障模式相同.我们还注意到该元素缺少 Window 属性,因为 IUIAutomationWindowPattern 不可访问.

解决方法可从 aforelinked 线程.代替 PropertyCondition,可以使用:

公共类 ConditionMatcher : IMatchConditions{公共布尔匹配(自动化元素元素,条件条件){return new TreeWalker(condition).Normalize(element) != null;}}

或者,也可以使用您提供的解决方法,前提是您的树结构保证是浅的(因此,适合该站点的名称,不会触发堆栈溢出).

诚然,这并不是最明显的问题.在完美的世界中,MSDN 应该有关于这个主题的更好的文档.

TL;DR: What am I doing wrong that is causing the workspace pane to show up in Inspect Objects but not show up in my custom code?


I am trying to write some UI automation to a 3rd party program. I am using Inspect.exe that came with the Windows SDK, and I have tried both System.Windows.Automation and direct COM Calls (using the wrapper library from UIA Verify).

Process[] processes = Process.GetProcessesByName("Redacted Client");
if (processes.Length == 0) throw new Exception("Could not find "Redacted Client" process");

PropertyCondition parentFileCond = new PropertyCondition(AutomationElement.ProcessIdProperty, processes[0].Id);
PropertyCondition workspaceCond = new PropertyCondition(AutomationElement.NameProperty, "Workspace", PropertyConditionFlags.IgnoreCase);
PropertyCondition documentCond = new PropertyCondition(AutomationElement.NameProperty, "Untitled3", PropertyConditionFlags.IgnoreCase);

var parentElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, parentFileCond);
var workspaceElement = parentElement.FindFirst(TreeScope.Children, workspaceCond); //Also does not work with TreeScope.Descendants
var documentElement = workspaceElement.FindFirst(TreeScope.Children, documentCond);

When I try the above code, parentElement does have the correct reference to the main program window, but workspaceElement is null.


A temporary workaround:

If I change my documentElement code to:

var documentElement = parentElement.FindFirst(TreeScope.Descendants, documentCond);

I will get the correct element returned. I can use this as a workaround as the document window is the one I really wanted anyway, but I would like to know why the Workspace pane would not show up so I can improve my skills in case I run into this in the future with a situation I cannot work around.


UPDATE: I tried MrGomez's suggestions

PropertyCondition parentFileCond = new PropertyCondition(AutomationElement.ProcessIdProperty, 5872);
PropertyCondition panelCond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane);

var parentElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, parentFileCond);
var panels = parentElement.FindAll(TreeScope.Children, panelCond);

I get 3 results, unfortunately, I have 4 panels, and the one that did not show up was the panel named Workspace.

I also tried to use a TreeWalker

PropertyCondition parentFileCond = new PropertyCondition(AutomationElement.ProcessIdProperty, 5872);
PropertyCondition workspaceCond= new PropertyCondition(AutomationElement.NameProperty, "Workspace");

var walker = new TreeWalker(workspaceCond);
var parentElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, parentFileCond);
var workspaceElement = walker.Normalize(parentElement);

but that also returns null for workspaceElement

Finally, in desperation, I tried the current value of "NativeWindowHandle" from Inspect and started the walking from the root node.

PropertyCondition workspaceCond = new PropertyCondition(AutomationElement.NativeWindowHandleProperty, 0x110906);
var walker = new TreeWalker(workspaceCond);
var workspaceElement = walker.Normalize(AutomationElement.RootElement);

Workspace element is STILL null.


Result Found

I finally did get Workspace to show up, but I had to perform

PropertyCondition workspaceCond = new PropertyCondition(AutomationElement.NativeWindowHandleProperty, 0x110906);
var test = AutomationElement.RootElement.FindFirst(TreeScope.Subtree, workspaceCond); 

and it took quite a while to run.

Old Screen Captures

Here is screenshots from Inspect.exe showing the tree view.

Here are the properties of the main window of the program.

How found:  Selected from tree...
RuntimeId:  "[42.2557552]"
BoundingRectangle:  {l:75 t:1 r:1311 b:1003}
ProcessId:  8160
ControlType:    UIA_WindowControlTypeId (0xC370)
LocalizedControlType:   "window"
Name:   "Redacted"
AccessKey:  ""
HasKeyboardFocus:   false
IsKeyboardFocusable:    true
IsEnabled:  true
ClassName:  "C:Program Files (x86)RedactedProgramFiles7RedactedClientFolder"
HelpText:   ""
IsPassword: false
NativeWindowHandle: 0x270670
IsOffscreen:    false
FrameworkId:    "Win32"
ProviderDescription:    "[pid:4000,hwnd:0x270670 Main:Nested [pid:8160,hwnd:0x270670 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]"
Window.CanMaximize: true
Window.CanMinimize: true
Window.WindowVisualState:   Normal (0)
Window.WindowInteractionState:  ReadyForUserInteraction (2)
Window.IsModal: false
Window.IsTopmost:   false
Transform.CanMove:  true
Transform.CanResize:    true
Transform.CanRotate:    false
LegacyIAccessible.ChildId:  0
LegacyIAccessible.DefaultAction:    ""
LegacyIAccessible.Description:  ""
LegacyIAccessible.Help: ""
LegacyIAccessible.KeyboardShortcut: ""
LegacyIAccessible.Name: "Redacted"
LegacyIAccessible.Role: client (0xA)
LegacyIAccessible.State:    focusable (0x100000)
LegacyIAccessible.Value:    ""
IsDockPatternAvailable: false
IsExpandCollapsePatternAvailable:   false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable:   false
IsLegacyIAccessiblePatternAvailable:    true
IsMultipleViewPatternAvailable: false
IsRangeValuePatternAvailable:   false
IsScrollPatternAvailable:   false
IsScrollItemPatternAvailable:   false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    false
IsTablePatternAvailable:    false
IsTableItemPatternAvailable:    false
IsTextPatternAvailable: false
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    true
IsValuePatternAvailable:    false
IsWindowPatternAvailable:   true
IsItemContainerPatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
IsSynchronizedInputPatternAvailable:    false
FirstChild: "Workspace" pane
LastChild:  "Application" menu bar
Next:   "Inspect  (HWND: 0x01700F06)" window
Previous:   "Sandbox Console (Debugging) - Microsoft Visual Studio (Administrator)" window
Other Props:    Object has no additional properties
Children:   "Workspace" pane
    (null) title bar
    "Application" menu bar
Ancestors:  "Desktop" pane
    [ No Parent ]

Here are the properties of the problem "Workspace" pane.

How found:  Selected from tree...
RuntimeId:  "[42.34146524]"
BoundingRectangle:  {l:83 t:51 r:1303 b:995}
ProcessId:  8160
ControlType:    UIA_PaneControlTypeId (0xC371)
LocalizedControlType:   "pane"
Name:   "Workspace"
AccessKey:  ""
HasKeyboardFocus:   false
IsKeyboardFocusable:    true
IsEnabled:  true
ClassName:  "MDIClient"
HelpText:   ""
IsPassword: false
NativeWindowHandle: 0x20908DC
IsOffscreen:    false
FrameworkId:    "Win32"
ProviderDescription:    "[pid:4000,hwnd:0x20908DC Main:Nested [pid:8160,hwnd:0x20908DC Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]"
LegacyIAccessible.ChildId:  0
LegacyIAccessible.DefaultAction:    ""
LegacyIAccessible.Description:  ""
LegacyIAccessible.Help: ""
LegacyIAccessible.KeyboardShortcut: ""
LegacyIAccessible.Name: "Workspace"
LegacyIAccessible.Role: client (0xA)
LegacyIAccessible.State:    focusable (0x100000)
LegacyIAccessible.Value:    ""
IsDockPatternAvailable: false
IsExpandCollapsePatternAvailable:   false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable:   false
IsLegacyIAccessiblePatternAvailable:    true
IsMultipleViewPatternAvailable: false
IsRangeValuePatternAvailable:   false
IsScrollPatternAvailable:   false
IsScrollItemPatternAvailable:   false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    false
IsTablePatternAvailable:    false
IsTableItemPatternAvailable:    false
IsTextPatternAvailable: false
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    false
IsValuePatternAvailable:    false
IsWindowPatternAvailable:   false
IsItemContainerPatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
IsSynchronizedInputPatternAvailable:    false
FirstChild: "Untitled3" window
LastChild:  "Letters (32638 of 32638):" window
Next:   (null) title bar
Previous:   [null]
Other Props:    Object has no additional properties
Children:   "Untitled3" window
    "Letters (32638 of 32638):" window
Ancestors:  "Redacted" window
    "Desktop" pane
    [ No Parent ]

Here are the properties of the "Working" document window.

How found:  Selected from tree...
RuntimeId:  "[42.9505096]"
BoundingRectangle:  {l:85 t:53 r:651 b:491}
ProcessId:  8160
ControlType:    UIA_WindowControlTypeId (0xC370)
LocalizedControlType:   "window"
Name:   "Untitled3"
AccessKey:  ""
HasKeyboardFocus:   false
IsKeyboardFocusable:    true
IsEnabled:  true
AutomationId:   "10"
ClassName:  "ProToolsSubMDIWndClass"
HelpText:   ""
IsPassword: false
NativeWindowHandle: 0x910948
IsOffscreen:    false
FrameworkId:    "Win32"
ProviderDescription:    "[pid:4000,hwnd:0x910948 Main:Nested [pid:8160,hwnd:0x910948 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]"
Window.CanMaximize: true
Window.CanMinimize: true
Window.WindowVisualState:   Normal (0)
Window.WindowInteractionState:  ReadyForUserInteraction (2)
Window.IsModal: false
Window.IsTopmost:   false
Transform.CanMove:  true
Transform.CanResize:    true
Transform.CanRotate:    false
LegacyIAccessible.ChildId:  0
LegacyIAccessible.DefaultAction:    ""
LegacyIAccessible.Description:  ""
LegacyIAccessible.Help: ""
LegacyIAccessible.KeyboardShortcut: ""
LegacyIAccessible.Name: "Untitled3"
LegacyIAccessible.Role: client (0xA)
LegacyIAccessible.State:    focusable (0x100000)
LegacyIAccessible.Value:    ""
IsDockPatternAvailable: false
IsExpandCollapsePatternAvailable:   false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable:   false
IsLegacyIAccessiblePatternAvailable:    true
IsMultipleViewPatternAvailable: false
IsRangeValuePatternAvailable:   false
IsScrollPatternAvailable:   false
IsScrollItemPatternAvailable:   false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    false
IsTablePatternAvailable:    false
IsTableItemPatternAvailable:    false
IsTextPatternAvailable: false
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    true
IsValuePatternAvailable:    false
IsWindowPatternAvailable:   true
IsItemContainerPatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
IsSynchronizedInputPatternAvailable:    false
FirstChild: "" thumb
LastChild:  (null) title bar
Next:   "Letters (32638 of 32638):" window
Previous:   [null]
Other Props:    Object has no additional properties
Children:   "" thumb
    (null) title bar
Ancestors:  "Workspace" pane
    "Redacted" window
    "Desktop" pane
    [ No Parent ]

解决方案

Very nice question. Based upon the problem you've documented, it's clear that your conditional:

PropertyCondition workspaceCond = new PropertyCondition(
 AutomationElement.NameProperty, "Workspace", PropertyConditionFlags.IgnoreCase);

... fails evaluation. Why?

The answer is how your conditional is evaluated. Looking at your element tree, we notice this property for Workspace:

IsWindowPatternAvailable:   false

And for the main window and Untitled3:

IsWindowPatternAvailable:   true

From MSDN:

UIA_IsWindowPatternAvailablePropertyId 30044

Identifies the IsWindowPatternAvailable property, which indicates whether the Window control pattern is available for the automation element. If TRUE, a client can retrieve an IUIAutomationWindowPattern interface from the element.

We find a repro in this thread, which implies the same failure pattern as the one you are currently experiencing. We also note the lack of Window properties present for this element because IUIAutomationWindowPattern is inaccessible.

A workaround is available from the aforelinked thread. Instead of PropertyCondition, one might use:

public class ConditionMatcher : IMatchConditions
{
    public bool Matches(AutomationElement element, Condition condition)
    {
        return new TreeWalker(condition).Normalize(element) != null;
    }
}

Or, alternately, one might use the workaround you've given, provided your tree structure is guaranteed to be shallow (and thus, appropriate to the name of this site, will not trigger a stack overflow).

Admittedly, this wasn't the most obvious issue. In the perfect world, MSDN should have better documentation on this topic.

这篇关于AutomationElement 使用 Inspect.exe 显示,但在使用 UIAutomationCore.dll 或 System.Windows.Automation 时不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆