Search code examples
pythonpython-3.xpywinauto

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


I trying expand or double_click() tree item. This code works just fine when rdp is open with mouse cursor and double_click_input(), but not working, when rdp closed because there isn't mouse cursor.

I trying methods click(), or double_click(), they not working.

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

If I try dlg.child_window(title="Система", control_type="TreeItem").print_control_identifiers()

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

How can I do this with pywinauto or it's impossible and I need to try it another way?

The are methods i get:

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']

Solution

  • All known recipes for remote execution are collected in the Remote Execution Guide.

    Probably you should customize RDP settings to allow minimizing/disconnection without losing active desktop.


    Below I describe less reliable methods which may not work for some apps like Qt5.

    Also for TreeItem it's worth trying method .select() which should use SelectionItem pattern. This pattern availability cab be checked in Inspect.exe. See the screenshot:

    enter image description here

    Also it's possible to try available patterns by menu "Action".

    P.S. For your case the available pattern is TableItem which is accessible by property (not method!) .iface_table_item. Just list all available methods for this pattern by built-in function dir():

    attrs = dir(dlg.child_window(title="Система", control_type="TreeItem").iface_table_item)
    print("Pattern object attributes: {}".format(attrs))
    

    The pattern object comes from UIAutomationCore.dll as a COM object. We don't use it anywhere in pywinauto yet, but it can be used and inspected as any normal Python object.