TreeItemWrapper object is not subscriptable
See original GitHub issueI have recently had to redo automation for one of our apps as the app changed significantly after a recent software update. We don’t develop or maintain the app, we just utilize it.
I have had to try to get all of the descendants of a window looking specifically at the tree items. Doing this returns a list of TreeItemWrapper elements. Looking at the documentation, I can find two conflicting (and possibly unchecked) definitions of what a TreeItemWrapper actually is.
Expected Behavior
According to documentation here, it is supposed to inherit click_input().
class pywinauto.controls.uia_controls.TreeItemWrapper(elem) Bases: pywinauto.controls.uiawrapper.UIAWrapper Wrap an UIA-compatible TreeItem control In addition to the provided methods of the wrapper additional inherited methods can be especially helpful: select(), extend(), collapse(), is_extended(), is_collapsed(), click_input(), rectangle() and many others
Actual Behavior
When dealing with the element, I am simply writing element[index].click_input() and the code breaks here. The exception thrown is:
‘TreeItemWrapper’ object is not subscriptable
The inclusion of click_input() is also not mentioned in the newer documentation. is this a bug? or was this something that was removed on purpose? Is there a way to make this work so I can click on that tree item?
Steps to Reproduce the Problem
- Get a list of tree item elements via
elements = app.descendants(control_type="TreeItem") - Pick a known index
elements[0].click_input() - Error is thrown.
Short Example of Code to Demonstrate the Problem
def openFile(file_name):
elements = dlg.window(title=App,class_name=appClass).descendants(control_type="TreeItem")
items = None
for element in elements:
#checking if the filename exists within the descendants list
if re.search(r".*"+re.escape(file_name)+r".*", str(element), re.IGNORECASE):
items = element
items[0].click_input() # Error is thrown here
Specifications
- Pywinauto version: 0.6.8
- Python version and bitness: Python 3.8 x64 bit
- Platform and OS: Windows 10 PC
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)

Top Related StackOverflow Question
I’ll keep my eyes open for future updates but use what I have for now. Thanks for the good work you guys are doing.
Probably
Inspect.exeusesRawTreeWalkerobject in MS UI Automation API while pywinauto uses functionFindAll(...)which sometimes provides different results especially for some “bugful” versions of Qt 5.x. We’re planning to addRawTreeWalkerusage as a default behavior. But other significant re-factoring is moving pretty slow.