The Windows Application Automating Using Pywinauto Does Not Detect Elements Inside A Treeview, Despite The Elements Have There Own Characteristic
Solution 1:
First, if you use Inspect.exe
you must use Application(backend="uia")
. If you want to check the application compatibility with older "win32" backend, you need Spy++ which is included into Visual Studio.
Second control_id
is integer ID from Spy++ and it can be inconsistent from run to run. I would recommend printing top level window texts by print([w.window_text() for w in app.windows()])
and use necessary text to identify top level window and dump child identifiers:
app.window(title="Main Window Title").dump_tree() # or use title_re for regular expression
app.window(title="Main Window Title").child_window(title="Sales Receipts", control_type="TreeItem").draw_outline().click_input()
# or get .wrapper_object() and discover all available methods,
# wrapper methods can be chained as above
P.S. If Inspect.exe
doesn't show property "NativeWindowHandle", it means the element is not visible to "win32" backend.
EDIT1:
Try this code for the "win32" TreeView which is not automatically detected as TreeViewWrapper:
from pywinauto import Application
from pywinauto.controls.common_controls import TreeViewWrapper
app = Application(backend="win32").connect(class_name="TFMenuG.UnicodeClass")
dlg = app['TFMenuG.UnicodeClass']
handle = dlg.child_window(class_name='THTreeView.UnicodeClass').wrapper_object().handle
tree_view = TreeViewWrapper(handle)
print(dir(tree_view)) # list all available methods
tree_view.get_item("Sales Receipts").expand()
tree_view.get_item(r"Sales Receipts\Reports").click(where="text")
When you see all available methods, try documented methods for "win32" TreeView: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.controls.common_controls.html#pywinauto.controls.common_controls.TreeViewWrapper Please note that _treeview_element
object returned by get_item(...)
represents specific item without window handle, but it's usable.
Post a Comment for "The Windows Application Automating Using Pywinauto Does Not Detect Elements Inside A Treeview, Despite The Elements Have There Own Characteristic"