question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dict_keys() is empty when trying to select a ListBox item

See original GitHub issue

I try to select an item in a ListBox (pywinauto 0.6.5). UPD: I work with Qt5 software.

The initial script just finds the certain drop down menu inside a dialog.

from pywinauto.application import Application
app = Application(backend='uia').start(r"app.exe")
dlg = app.window(best_match='Select Rename Device')
dlg.window(best_match='DownComboBox3').print_control_identifiers()

The output seems to be good:

ComboBox - ' Down'    (L795, T522, R1157, B542)
['ComboBox', ' DownComboBox', ' Down']
child_window(title=" Down", control_type="ComboBox")
   | 
   | ListBox - ''    (L0, T0, R0, B0)
   | ['', 'ListBox']
   |    | 
   |    | ListItem - '00/4i Simulation mode'    (L1, T1, R752, B24)
   |    | ['00/4i Simulation mode', '00/4i Simulation modeListItem', 'ListItem', 'ListItem0', 'ListItem1']
   |    | child_window(title="00/4i Simulation mode", control_type="ListItem")
   |    | 
   |    | ListItem - '00/2i Simulation mode'    (L1, T24, R752, B47)
   |    | ['00/2i Simulation mode', '00/2i Simulation modeListItem', 'ListItem2']
   |    | child_window(title="00/2i Simulation mode", control_type="ListItem")
   |    | 
   |    | ListItem - '00/6i Simulation mode'    (L1, T47, R752, B70)
   |    | ['00/6i Simulation mode', '00/6i Simulation modeListItem', 'ListItem3']
   |    | child_window(title="00/6i Simulation mode", control_type="ListItem")

Process finished with exit code 0

Now I try to select ‘00/2i Simulation mode’ ListItem:

from pywinauto.application import Application
app = Application(backend='uia').start(r"app.exe")
dlg = app.window(best_match='Select Rename Device')
dlg.window(best_match='DownComboBox3').child_window(best_match='00/2i Simulation mode').select()

but got an error: pywinauto.findbestmatch.MatchError: Could not find '00/2i Simulation mode' in 'dict_keys([])'

I tried to apply workaround suggested in the issue #365 but the error was the same:

from pywinauto.application import Application
app = Application(backend='uia').start(r"app.exe")
dlg = app.window(best_match='Select Rename Device')
dlg.window(best_match='DownComboBox3').ListBox.child_window(title="00/2i Simulation mode", control_type="ListItem").select()

Also, I tried to change backend to win32 (as #467 suggested).

But the dict_keys() was still empty.

I have no idea where I’m wrong. May anybody suggests a way to solve this issue with drop-down menu selection?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vnabokitcommented, Aug 31, 2018

Use Case. Select an item from ComboBox control for an Qt5.6 application.

App example: https://fex.net/485689299381 (it is standard ‘blockingslave.exe’ Qt app compiled via QtCreator using MinGW) Note: Activate a COM port before using this app (I plugged an USB device, USB type B)

Actual Result: Such constructions do not work:

dlg.child_window(title=' Down').child_window(best_match='ListBox').select('COM12')

or

dlg.ComboBox.child_window(best_match='ListBox').select('COM12')

or

dlg.ComboBox.ListBox.select(0)

Expected Result: Ability to make selection by any way.

Full script code:

from pywinauto.application import Application
import time

app_full_path = r'C:\Qt56\Examples\Qt-5.6\serialport\build-blockingslave-Desktop_Qt_5_6_2_MinGW_32bit-Debug\debug\blockingslave.exe'
app = Application(backend='uia').start(app_full_path)
time.sleep(2)
dlg = app.window(best_match='Dialog')
dlg.child_window(title=' Down').child_window(best_match='ListBox').select('COM12')

Screens: screenshot_25 screenshot_24 screenshot_23

0reactions
vasily-v-ryabovcommented, Oct 10, 2021

Method .select() for combo box should work well now (in atspi branch). So we’re closing the issue. The fix will be included into next major release (no exact deadline though).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to display a Dictionary in a ListBox - Stack Overflow
Use the Format event on the list box: KeyValuePair<string, int> item = (KeyValuePair<string, int>)e.ListItem; e.Value = string.
Read more >
How to get selected value from listbox in tkinter?
It is executed when we press the “Print Selected” button. In the case of no selected items, curselection method returns an empty tuple....
Read more >
VBA Listbox - A Complete Guide - Excel Macro Mastery
The ListBox is used to display a list of items to the user so that the user can then select one or more....
Read more >
Google Visualization API Reference | Charts
Each row is an object as described in addRow() . Use null or an empty array entry for an empty cell. Example: data....
Read more >
Dropdown | Dash for Python Documentation | Plotly
loading_state (dict; optional): Object that holds the loading state object coming from dash-renderer. loading_state is a dict with keys: component_name (string; ...
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