我如何在没有 RDP 的情况下使用 pywinauto 展开或双击 TreeItem

how can i expand or double click TreeItem without RDP with pywinauto

我正在尝试展开或 double_click() 树项目。 当使用鼠标光标和 double_click_input() 打开 rdp 时,这段代码工作正常,但当 rdp 关闭时因为没有鼠标光标而无法正常工作。

我尝试了 click() 或 double_click() 方法,但它们不起作用。

app = Application(backend="uia").connect(title='myApplication')
dlg = app.window(title='Control Panel of myApplication')

#this click() works without rdp
dlg.child_window(auto_id="MainPanelForm.gridLayoutWidget.MainPanelWidget.rightFrame.setupWidget.setupButton").click()
dlg.child_window(title="Система", control_type="TreeItem").double_click_input()

inspect.exe inspect.exe

如果我尝试 dlg.child_window(title="Система", control_type="TreeItem").print_control_identifiers()

TreeItem - 'Система'    (L3102, T196, R3877, B220)
['СистемаTreeItem', 'Система', 'TreeItem']
child_window(title="Система", control_type="TreeItem")

我怎样才能用 pywinauto 做到这一点,或者这是不可能的,我需要用另一种方式尝试?

我得到的方法有:

Pattern object attributes: ['AddRef', 'GetCachedColumnHeaderItems',
'GetCachedRowHeaderItems', 'GetCurrentColumnHeaderItems',
'GetCurrentRowHeaderItems', 'QueryInterface', 'Release', '_AddRef',
'_IUIAutomationTableItemPattern__com_GetCachedColumnHeaderItems',
'_IUIAutomationTableItemPattern__com_GetCachedRowHeaderItems',
'_IUIAutomationTableItemPattern__com_GetCurrentColumnHeaderItems',
'_IUIAutomationTableItemPattern__com_GetCurrentRowHeaderItems',
'_IUnknown__com_AddRef', '_IUnknown__com_QueryInterface',
'_IUnknown__com_Release', '_QueryInterface', '_Release', '__bool__',
'__class__', '__cmp__', '__com_interface__', '__ctypes_from_outparam__',
'__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__',
'__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
'__map_case__', '__module__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__setstate__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_b_base_',
'_b_needsfree_', '_case_insensitive_', '_compointer_base__get_value',
'_idlflags_', '_iid_', '_methods_', '_needs_com_addref_', '_objects',
'_type_', 'from_param', 'value']

所有已知的远程执行配方都收集在 Remote Execution Guide

可能您应该自定义 RDP 设置以允许 minimizing/disconnection 而不会丢失活动桌面。


下面我描述了不太可靠的方法,这些方法可能不适用于 Qt5 等某些应用程序。

同样对于 TreeItem,值得尝试的方法 .select() 应该使用 SelectionItem 模式。此模式可用性可在 Inspect.exe 中检查。见截图:

也可以通过菜单“操作”尝试可用的模式。

P.S。对于您的情况,可用模式是 TableItem,可通过 属性(不是方法!).iface_table_item 访问。只需通过内置函数 dir():

列出此模式的所有可用方法
attrs = dir(dlg.child_window(title="Система", control_type="TreeItem").iface_table_item)
print("Pattern object attributes: {}".format(attrs))

模式对象作为 COM 对象来自 UIAutomationCore.dll。我们还没有在 pywinauto 的任何地方使用它,但它可以像任何普通的 Python 对象一样使用和检查。