Search code examples
pythoncomboboxpywinauto

Controlling nonstandard classes with pywinauto


I am using pywinauto in order to ease my work with certain program. I would like to select in this combobox item "vs. Reference". I used app['Setup Potentiodynamic Experiment'].PrintControlIdentifiers() to get name and class of the combobox. Python returned the following:

TComboDJ - 'b'vs. Open Circuit''   (L987, T424, R1094, B445)

'b'TComboDJ5''
'b'vs. Open Circuit3''
'b'vs. Open CircuitTComboDJ3''

So, to do what I want, I used this:

app['Setup Potentiodynamic Experiment']["TComboDJ5"].Select("vs. Reference")

And the following error appeared:

Exception in Tkinter callback
Traceback (most recent call last):
  File "E:\PY\lib\tkinter\__init__.py", line 1550, in __call__
    return self.func(*args)
  File "E:/Python projects/test/test.py", line 40, in createxp
    app['Setup Potentiodynamic Experiment']["TComboDJ5"].Select("vs. Reference")
  File "E:\PY\lib\site-packages\pywinauto\application.py", line 245, in __getattr__
    return getattr(ctrls[-1], attr)
AttributeError: 'HwndWrapper' object has no attribute 'Select'

As far as I understand, pywinauto can't recognize the combobox as a combobox. Can something be done about it?


Solution

  • ComboBoxWrapper can be created explicitly:

    from pywinauto.controls.win32_controls import ComboBoxWrapper
    hwnd_wr = app['Setup Potentiodynamic Experiment']["TComboDJ5"].WrapperObject()
    combo = ComboBoxWrapper(hwnd_wr)
    combo.Select("vs. Reference")
    

    Of course it would work if the combo box could respond to standard window messages like CB_GETCOUNT. And the output tells you that combined <title><item_text> access names are fortunately available.