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.

TreeItemWrapper object is not subscriptable

See original GitHub issue

I 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

  1. Get a list of tree item elements via elements = app.descendants(control_type="TreeItem")
  2. Pick a known index elements[0].click_input()
  3. 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:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jkwhite91commented, Jan 7, 2020

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.

0reactions
vasily-v-ryabovcommented, Jan 7, 2020

Probably Inspect.exe uses RawTreeWalker object in MS UI Automation API while pywinauto uses function FindAll(...) which sometimes provides different results especially for some “bugful” versions of Qt 5.x. We’re planning to add RawTreeWalker usage as a default behavior. But other significant re-factoring is moving pretty slow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error in program(TypeError: 'type' object is not subscriptable)
The error you mention is here on your first line: s=list[4,5,67,11]. the list is a type in python. It seems that you want...
Read more >
Python TypeError: 'function' object is not subscriptable Solution
The “TypeError: 'function' object is not subscriptable” error occurs when you try to access a function as if it were an iterable object....
Read more >
How to Fix Object is Not Subscriptable In Python - YouTube
In this quick tutorial we will explore how to fix ' Object Is Not Subscriptable ' in python. A subscriptable object describes objects...
Read more >
How To Fix Type Error: Type Object is not Subscriptable
Are you wondering How To Fix Type Error: Type Object is not Subscriptable and have not found a good video that explains why...
Read more >
'function' object is not subscriptable Solution - YouTube
Python TypeError: 'function' object is not subscriptable Solution#typerror | #function | #pythonDLK Career Development offers training ...
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