Jump to content

Clicking a ComboBox item when the drop-down is outside the original window

Recommended Posts

I'm trying to write an automation script which clicks an item in a WinForms ComboBox. I am able to click the field and get the list to appear, but I cannot click the item in the list. I tried using the following code first

ControlClick("MyProgram", "", "[ID:462328]")
ControlClick("MyProgram", "", "[TEXT:API_PERFORMANCE]")

This correctly opens the drop-down, but it does not click the desired value (list item "API_PERFORMANCE"). Using the Window Info tool on the item yields me a control with CLASS:Progman and TEXT:Program Manager. I did some poking around the internet, and found that, in older versions of WinForms, ComboBox lists and their items are created outside of the original program, on the desktop, so I tried the following code.

ControlClick("MyProgram", "", "[ID:462328]")
ControlClick("[CLASS:Progman]", "", "[TEXT:API_PERFORMANCE]")

This still does not click anything. I am unsure how to proceed at this point. I used the Microsoft-provided inspect.exe tool to get the following information about the control.

How found:  Mouse move (-1596,436)
    hwnd=0x0000000000070C34 64bit class="ComboLBox" style=0x54A08041 ex=0x88
ControlType:    UIA_ListItemControlTypeId (0xC357)
LocalizedControlType:   "list item"
BoundingRectangle:  {l:-1642 t:431 r:-1531 b:444}
IsEnabled:  true
IsOffscreen:    false
IsKeyboardFocusable:    true
HasKeyboardFocus:   false
AccessKey:  ""
ProcessId:  6304
RuntimeId:  [2A.70C34.4.80000001.70C34.FFFFFFFC.3]
ProviderDescription:    "[pid:6304,providerId:0x0 Annotation:Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]"
IsPassword: false
HelpText:   ""
IsDialog:   [Not supported]
LegacyIAccessible.ChildId:  3
LegacyIAccessible.DefaultAction:    "Double Click"
LegacyIAccessible.Description:  ""
LegacyIAccessible.Help: ""
LegacyIAccessible.KeyboardShortcut: ""
LegacyIAccessible.Name: "API_PERFORMANCE"
LegacyIAccessible.Role: list item (0x22)
LegacyIAccessible.State:    selected,focusable,selectable (0x300002)
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
IsCustomNavigationPatternAvailable: false
IsSelectionPattern2Available:   false
FirstChild: [null]
LastChild:  [null]
Next:   "CSharp" list item
Previous:   "API" list item
Other Props:    Object has no additional properties
Children:   Container has no children
Ancestors:  "" list
    "Desktop 1" pane
    [ No Parent ]

Is there anything in there that I could use to locate this element and click it? Or is there something I'm missing here?

Link to post
Share on other sites

Look at ControlCommand () function (especially the part about ComboBox) .  The way you are trying to do it will never work.  Also there is a GUI Combo Box UDF that have additional functionalities that you could use.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...