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 expressionapp.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附言如果 Inspect.exe 未显示属性NativeWindowHandle",则表示该元素对win32"不可见;后端.P.S. If Inspect.exe doesn't show property "NativeWindowHandle", it means the element is not visible to "win32" backend.试试这个win32"代码未被自动检测为 TreeViewWrapper 的 TreeView:Try this code for the "win32" TreeView which is not automatically detected as TreeViewWrapper:from pywinauto import Applicationfrom pywinauto.controls.common_controls import TreeViewWrapperapp = Application(backend="win32").connect(class_name="TFMenuG.UnicodeClass")dlg = app['TFMenuG.UnicodeClass']handle = dlg.child_window(class_name='THTreeView.UnicodeClass').wrapper_object().handletree_view = TreeViewWrapper(handle)print(dir(tree_view)) # list all available methodstree_view.get_item("Sales Receipts").expand()tree_view.get_item(r"Sales Receipts\Reports").click(where="text")当您看到所有可用的方法时,请尝试win32"的文档化方法;树视图:https://pywinauto.readthedocs.io/en/latest/code/pywinauto.controls.common_controls.html#pywinauto.controls.common_controls.TreeViewWrapper 请注意get_item(...) 表示没有窗口句柄的特定项,但它是可用的.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. 这篇关于尽管元素具有自己的特征,但使用 pywinauto 自动化的 Windows 应用程序不会检测到 TreeView 中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 05-19 16:00