Search code examples
python-3.xpywinauto

pywinauto doesn't see ListView object using .print_control_identifiers()


I am evaluating pywinauto library to be able to automate win desktop applications and so far it looks very promising. For evaluation I am using simple BookDB2 app which I used many times before (e.g.: by testComplete or UFT evaluations). Unlike other objects in this app - which I am able to find and work with, pywinauto for some reason cannot see its ListView object.

When used:

from pywinauto.application import Application
app = Application(backend='uia').start(r"C:\Program Files (x86)\BookDB2\BookDB2.exe")
app.top_window().print_control_identifiers()

python prints all found objects to log, however ListView object is missing. I also tried to find it directly using its properties (with help of AutoIt spy tool), but was unsuccessful. Normally I would think that this ListView is customized (non-standard) - because that could be good explanation why it is not recognized. But I know that UFT and testComplete did not have a slightest problem to recognize&work with it. What am I missing?

Update: I tried SWAPY - which is kind of pywinauto support tool capable of object spying and generating simple code.

I found out that SWAPY actually can see this ListView object and it generated for me click operation:

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Program Files (x86)\\BookDB2\\BookDB2.exe" ')
thunderrtformdc = app[u'BookDB Main Menu']
thunderrtformdc.Wait('ready')
listviewwndclass = thunderrtformdc[u'3']
listviewwndclass.Click()

app.Kill_()

When executed in PyCharm - this error appeared:

    raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find '3' in 'dict_keys(['ThunderRT6Frame', 'FiltersThunderRT6Frame', 'Filters', 'ApplyButton', 'Button', 'Apply', 'ClearButton', 'Button0', 'Button1', 'Button2', 'Clear', 'Add BookEdit', 'Edit', 'Add BookEdit0', 'Add BookEdit1', 'Add BookEdit2', 'Edit0', 'Edit1', 'Edit2', 'ComboBox', 'ApplyComboBox', 'ComboBox0', 'ComboBox1', 'ComboBox2', 'Add BookComboBox', 'Button3', 'Copies', 'CopiesButton', 'Button4', 'Add Book', 'Add BookButton', 'BooksListView', 'ListView', 'BooksHeader', 'Header', 'Button5', 'BorrowersButton', 'Borrowers', 'Button6', 'CategoriesButton', 'Categories', 'Button7', 'Publishers', 'PublishersButton', 'Authors', 'Button8', 'AuthorsButton', 'Button9', 'BooksButton', 'Books'])'

So it seems to me that SWAPY sees something which pywinauto cannot.


Solution

  • Ok... so it was all my mistake. This is correct:

    app = Application().start(r"C:\Program Files (x86)\BookDB2\BookDB2.exe")
    

    for some reason I forgot backend='uia' in code when starting the app, probably copy&paste error. Still not sure why other objects were visible and this (ListView) wasn't but at least my problem is solved.