Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Windows Automation to find and invoke a button that has no ancestors

We are trying to automate a click of the following button in the Lync interface. The problem is that we cannot reliably click it. Sometimes it works; other times it doesn't. What we are trying to accomplish is to open the Lync options window.

Here are some parts of the problem:

  • we are using the System.Windows.Automation namespace for UI automation.
  • usually we call AutomationElement.FindFirst to get UI element
  • this doesn't work for the button, because the button's menu does NOT have any ancestor
  • so, we use the TreeWalker to walk all descendants of AutomomationElement.RootElement
  • using the TreeWalker, we sometimes find a match, but oddly and unpredictably we sometimes don't
  • using Inspect.exe we can see that the button's "Context" menu does not have any ancestors

How can we reliably find and click the button?

The context menu of doom.

Inspect.exe

From Inspect.exe

How found:  Selected from tree...
Name:   ""
ControlType:    UIA_MenuItemControlTypeId (0xC35B)
LocalizedControlType:   "menu item"
ProcessId:  0
IsControlElement:   true
IsContentElement:   true
ProviderDescription:    "[pid:3084,hwnd:0x0 Annotation:Microsoft: Annotation Proxy (unmanaged:UIAutomationCore.dll); Main(parent link):Microsoft: MSAA Proxy (unmanaged:UIAutomationCore.dll)]"
IsPeripheral:   [Not supported]
LiveSettingProperty:    [Not supported]
FlowsFrom:  [Not supported]
OptimizeForVisualContent:   [Not supported]
Annotation.AnnotationAuthor:    [Not supported]
Annotation.AnnotationTypeId:    [Not supported]
Annotation.Author:  [Not supported]
Annotation.DateTime:    [Not supported]
Annotation.Target:  [Not supported]
Drag.DropEffect:    [Not supported]
Drag.DropEffects:   [Not supported]
Drag.GrabbedItems:  [Not supported]
Drag.IsGrabbed: [Not supported]
DropTarget.DropTargetEffect:    [Not supported]
DropTarget.DropTargetEffects:   [Not supported]
LegacyIAccessible.ChildId:  3
LegacyIAccessible.Name: ""
ObjectModel.UnderlyingObjectModel:  [Error: calling getter for this property: hr=0x80070057 - The parameter is incorrect.]
SpreadsheetItem.AnnotationObjects:  [Not supported]
SpreadsheetItem.AnnotationTypes:    [Not supported]
SpreadsheetItem.Formula:    [Not supported]
Style.ExtendedProperties:   [Not supported]
Style.FillColor:    [Not supported]
Style.FillPatternColor: [Not supported]
Style.FillPatternStyle: [Not supported]
Style.Shape:    [Not supported]
Style.StyleId:  [Not supported]
Style.StyleName:    [Not supported]
Transform2.CanZoom: [Not supported]
Transform2.ZoomLevel:   [Not supported]
Transform2.ZoomMinimum: [Not supported]
Transform2.ZoomMaximum: [Not supported]
IsAnnotationPatternAvailable:   [Not supported]
IsDragPatternAvailable: [Not supported]
IsDockPatternAvailable: false
IsDropTargetPatternAvailable:   [Not supported]
IsExpandCollapsePatternAvailable:   false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable:   false
IsItemContainerPatternAvailable:    false
IsLegacyIAccessiblePatternAvailable:    true
IsMultipleViewPatternAvailable: false
IsObjectModelPatternAvailable:  [Not supported]
IsRangeValuePatternAvailable:   false
IsScrollItemPatternAvailable:   false
IsScrollPatternAvailable:   false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    false
IsSpreadsheetItemPatternAvailable:  [Not supported]
IsSpreadsheetPatternAvailable:  [Not supported]
IsStylesPatternAvailable:   [Not supported]
IsSynchronizedInputPatternAvailable:    false
IsTableItemPatternAvailable:    false
IsTablePatternAvailable:    false
IsTextChildPatternAvailable:    [Not supported]
IsTextEditPatternAvailable: [Not supported]
IsTextPatternAvailable: false
IsTextPattern2Available:    [Not supported]
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    false
IsTransform2PatternAvailable:   [Not supported]
IsValuePatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
IsWindowPatternAvailable:   false
FirstChild: [null]
LastChild:  [null]
Next:   [null]
Previous:   [null]
Other Props:    Object has no additional properties
Children:   [Error: calling getter for this property: hr=0x80004005 - Unspecified error]
Ancestors:  "Context" menu
    "Context" window
    [ No Parent ]
like image 696
Shaun Luttin Avatar asked Nov 02 '22 03:11

Shaun Luttin


1 Answers

How about opening the drop down menu via UIA and then using SendKeys to send Alt-D ("%d")?

like image 189
DoronG Avatar answered Nov 15 '22 04:11

DoronG