Unable to retrieve all information from ComboBox selection

See original GitHub issue

I’m new to pywinauto and uia, but I’m hoping you can help me with an issue.

I’m trying to retrieve information about the selected item in some sort of ComboBox. I’ve noticed that the ComboBox items don’t populate until I run expand(), but I’m only interested in what’s currently displayed (see image below). Inspect.exe shows me that ComboBoxEdit has three children, all three children correspond to the selected item it seems - not to a combobox list. But pywinauto only detects the first child ‘Image’, not the other two pieces of text.

fc

Is there any way I can retrieve the other two children “FC 123-456789” and “123-456789”? I’m wondering if this is a non-standard combobox that pywinauto doesn’t understand.

The following code gives control_count = 1. I thought the missing children might be accessible in the ‘Image’ control but I haven’t found anything.

from pywinauto.application import Application

app = Application(backend="uia").connect(path="Program.exe")

# be picky about the title in case two windows are open
dlg = app.window(title_re=".*Program.*")

cbo = dlg.ComboBox

print(cbo.wrapper_object().control_count())

Inspect.exe:

How found:	Mouse move (299,838)
	hwnd=0x000A0E1E 64bit class="HwndWrapper[Program.exe;;15de3ec8-8cf3-4e77-a2af-ef9b415fa0a8]" style=0x17CF0000 ex=0x40100
RuntimeId:	"[7.12152.24717373]"
BoundingRectangle:	{l:39 t:824 r:360 b:864}
ProcessId:	12152
ControlType:	UIA_ComboBoxControlTypeId (0xC353)
LocalizedControlType:	"combo box"
Name:	""
AcceleratorKey:	""
AccessKey:	""
HasKeyboardFocus:	true
IsKeyboardFocusable:	true
IsEnabled:	true
AutomationId:	""
ClassName:	"ComboBoxEdit"
HelpText:	""
ClickablePoint:	{x:199 y:844}
IsControlElement:	true
IsContentElement:	true
IsPassword:	false
ItemType:	""
IsOffscreen:	false
Orientation:	0
FrameworkId:	"WPF"
IsRequiredForForm:	false
ItemStatus:	""
ProviderDescription:	"[pid:12152,hwnd:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]"
Value.IsReadOnly:	false
Value.Value:	"MIP.Platform.Domain"
Selection.Selection:	
Selection.CanSelectMultiple:	false
Selection.IsSelectionRequired:	false
ExpandCollapse.ExpandCollapseState:	Collapsed (0)
IsDockPatternAvailable:	false
IsExpandCollapsePatternAvailable:	true
IsGridItemPatternAvailable:	false
IsGridPatternAvailable:	false
IsInvokePatternAvailable:	false
IsMultipleViewPatternAvailable:	false
IsRangeValuePatternAvailable:	false
IsScrollPatternAvailable:	false
IsScrollItemPatternAvailable:	false
IsSelectionItemPatternAvailable:	false
IsSelectionPatternAvailable:	true
IsTablePatternAvailable:	false
IsTableItemPatternAvailable:	false
IsTextPatternAvailable:	false
IsTogglePatternAvailable:	false
IsTransformPatternAvailable:	false
IsValuePatternAvailable:	true
IsWindowPatternAvailable:	false
IsItemContainerPatternAvailable:	false
IsVirtualizedItemPatternAvailable:	false
FirstChild:	"" image
LastChild:	"123-456789" text
Next:	"Incubator: Off" text
Previous:	"" custom
Other Props:	Object has no additional properties
Children:	"" image
	"FC 123-456789" text
	"123-456789" text
Ancestors:	"" custom
	"Session tree" group
	"" custom
	"PART_ContentPresenter" group
	"script v0.1" group
	"DocumentGroup" tab
	"LayoutGroup" group
	"DockLayoutManager" group
	"BarManagerbarManager" group
	"" custom
	"script v0.1 - Program" window
	"Desktop" pane
	[ No Parent ]

dump_tree excerpt:

   |    |    |    |    |    |    |    |    |    | Custom - ''    (L39, T824, R360, B995)
   |    |    |    |    |    |    |    |    |    | ['99', 'Custom41']

   |    |    |    |    |    |    |    |    |    |    | 
   |    |    |    |    |    |    |    |    |    |    | Custom - ''    (L0, T0, R0, B0)
   |    |    |    |    |    |    |    |    |    |    | ['100', 'Custom42']

   |    |    |    |    |    |    |    |    |    |    | 
   |    |    |    |    |    |    |    |    |    |    | ComboBox - ''    (L39, T824, R360, B864)
   |    |    |    |    |    |    |    |    |    |    | ['101', 'ComboBox', 'MIP.Platform.Domain']

   |    |    |    |    |    |    |    |    |    |    |    | 
   |    |    |    |    |    |    |    |    |    |    |    | Image - ''    (L44, T829, R74, B859)
   |    |    |    |    |    |    |    |    |    |    |    | ['102', 'Image20']

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
harryhobsoncommented, Dec 17, 2017

I began experimenting with FlaUI and might have made some progress on this issue.

FlaUI has a wiki section that was able to fix the problem of the 2 TextBlocks not appearing in the image in my first post. My problematic textblocks have IsControlElement=false and IsContentElement=false, but the RawViewWalker is able to find these elements. The relevant code for finding these elements with FlaUI is here.

A few weeks back, I tried to replicate the pywinauto element finding method in FlaUI. This involved running the AutomationElement.FindAll method like from here. I think I found that the FindAll method does not return these TextBlock elements, but RawViewWalker does. So it’s an issue with automationelement.findall, not a bug in pywinauto.

Any chance you would be able to implement RawViewWalker for finding elements? I have no idea what other issues this may cause… I would like to give this a crack myself but with job changes I haven’t found the time. I would like to move my automation project from FlaUI/C# to pywinauto/Python at some stage in the next 6 months. Will give it a crack then if you don’t find time.

Don’t have an update on the listbox item selection error at this stage

1reaction
vasily-v-ryabovcommented, Nov 3, 2017

@airelil it looks like ControlType: UIA_ComboBoxControlTypeId (0xC353) is correct to detect it as ComboBox. Class name string matters for Win32 backend only as I remember.

Hi @harryhobson maybe .children(content_only=True) would help. Because these texts are content elements, not a control ones.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to read existing value in combo box
Hi, When edit a form, I am unable to read the existing data using active.selected.value. It is giving me blank value.
Read more >
Unable to retrieve data from combobox. - Stack Overflow
I am trying to display the result from an if statment which is based upon the option selected within a windows form combo...
Read more >
Combo box control in Power Apps | Search, Filter, Large Data ...
In this PowerApps video, you will learn all about the combo box control.A combobox control is one that allows users to make selections...
Read more >
Power Apps Combo Box DefaultSelectedItems - YouTube
It is no secret that the Combo box is a grumpy control. So in this video I break down how to make it...
Read more >
Unable to select value inside Combobox using UIA
I have an issue while selecting a value present inside a combo box . 1. Spied the element using UIA mode and checked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found