Search code examples
python-3.xpywinauto

pywinauto double click on TreeItem (or open and double click inside)


I have and application with a list of TreeViews and TreeItems and I need to "double click" in one TreeItem, but I can't find the way to do it.

This is my python code:

#Open Application
app = Application(backend="uia").start(ApplicationName, wait_for_idle=True)
time.sleep(2)
dlg = app.top_window()


#Pass and login
app.dlg.child_window(title="", auto_id="LoginAuthPasswordBox", control_type="Edit").set_text('******')
app.dlg.child_window(auto_id="Inici_o de sesión", control_type="Button").click()

time.sleep(60)

#Connect to main window
appfull = Application(backend="uia").connect(title_re="IC Business Manager - Interaction Reporter")
dlgfull = appfull.top_window()

This code is working OK and, inside dlgfull.print_control_identifiers() I got this: https://i.sstatic.net/NtJM8.png

And this is mi app: https://i.sstatic.net/7QWyB.png

I would like to "double click" the first item "Informe estados de agente", OR open it and double clic the first item inside: https://i.sstatic.net/PHYQy.png

Could you please help me on this?

Some lines that i've testing and doesn't work:

appfull.dlgfull.child_window(title="Informe de estados de agentes", control_type="TreeItem")..click()

dlgfull.child_window(title="Informe de estados de agentes", control_type="TreeItem").click()

appfull.dlgfull.child_window(title="Informe de estados de agentes", control_type="TreeItem").double_click()

appfull.dlgfull.child_window(title="Informe de estados de agentes", control_type="TreeItem").get_child(child_spec="agentes").click()

Thanks!


Solution

  • Use GetItem() along with select() or click() method, you can also use expand() method to expand and view elements that are not visible.

    treeView = topWin.TreeView    # We get the treeview object here.
    # You can get item like this 
    node1 = treeView.GetItem([u'TopNodeName', 'node1Name'])
    node1.select()
    
    # OR something like this
    treeView.GetItem([u'TopNodeName', 'node1Name']).click()
    
    # OR access using index of that element in treeview like:
    treeView.GetItem([1, 0]).click()