I’m trying to do some automation actions using UI Automation. I can get the target UI element by code. And I can see its property IsInvokePatternAvailable is true. But when I tried to get the InvokePattern it shows me “System.InvalidOperationException: Unsupported Pattern.”
Then I want to check what are the supported patterns by the API “GetSupportedPatterns”, and I found there was only one pattern “SelectionItemPattern”.
Interestingly, if I use the Inovke.invoke command from the action menu of Inspect.exe, it works.
So I suppose there should be a method that can be invoked. The issue has blocked me a couple of days. Who can give me some clues?
Exception
Inspect Tool
How found: Focus
Name: "Select group:"
ControlType: UIA_ListItemControlTypeId (0xC357)
LocalizedControlType: "list item"
BoundingRectangle: {l:642 t:280 r:770 b:293}
IsEnabled: true
IsOffscreen: false
IsKeyboardFocusable: true
HasKeyboardFocus: true
AccessKey: ""
ProcessId: 12956
RuntimeId: [2A.32270.4.80000001.32270.FFFFFFFC.1]
ProviderDescription: "[pid:12956,providerId:0x0 Annotation:Microsoft: Annotation Proxy (unmanaged:UIAutomationCore.dll); Main(parent link):Microsoft: MSAA Proxy (unmanaged:UIAutomationCore.dll)]"
IsPassword: false
HelpText: ""
LegacyIAccessible.ChildId: 1
LegacyIAccessible.DefaultAction: "Double Click"
LegacyIAccessible.Description: ""
LegacyIAccessible.Help: ""
LegacyIAccessible.KeyboardShortcut: ""
LegacyIAccessible.Name: "Select group:"
LegacyIAccessible.Role: list item (0x22)
LegacyIAccessible.State: selected,focused,focusable,selectable (0x300006)
LegacyIAccessible.Value: ""
SelectionItem.IsSelected: true
SelectionItem.SelectionContainer: "" list
IsAnnotationPatternAvailable: false
IsDragPatternAvailable: false
IsDockPatternAvailable: false
IsDropTargetPatternAvailable: false
IsExpandCollapsePatternAvailable: false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable: true
IsItemContainerPatternAvailable: false
IsLegacyIAccessiblePatternAvailable: true
IsMultipleViewPatternAvailable: false
IsObjectModelPatternAvailable: false
IsRangeValuePatternAvailable: false
IsScrollItemPatternAvailable: true
IsScrollPatternAvailable: false
IsSelectionItemPatternAvailable: true
IsSelectionPatternAvailable: false
IsSpreadsheetItemPatternAvailable: false
IsSpreadsheetPatternAvailable: false
IsStylesPatternAvailable: false
IsSynchronizedInputPatternAvailable: false
IsTableItemPatternAvailable: false
IsTablePatternAvailable: false
IsTextChildPatternAvailable: false
IsTextEditPatternAvailable: false
IsTextPatternAvailable: false
IsTextPattern2Available: false
IsTogglePatternAvailable: false
IsTransformPatternAvailable: false
IsTransform2PatternAvailable: false
IsValuePatternAvailable: false
IsVirtualizedItemPatternAvailable: false
IsWindowPatternAvailable: false
FirstChild: [null]
LastChild: [null]
Next: "xxx" list item
Previous: [null]
Other Props: Object has no additional properties
Children: Container has no children
Ancestors: "" list
AutomationElementCollection mats = list1.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
foreach (AutomationElement mat in mats)
{
InvokePattern matInvoke = (InvokePattern)mat.GetCurrentPattern(InvokePattern.Pattern);
matInvoke.Invoke();
}
Albert Shang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.