With this code I get not the first element I got, but the last one:

from pywinauto.application import Application app = Application().connect(class_name='CommunicatorMainWindowClass') window = app.window(class_name='CommunicatorMainWindowClass') # window.print_control_identifiers() window.NetUINativeHWNDHost.NetUIHWND.print_control_identifiers() print() rich_edit = window.NetUINativeHWNDHost.NetUIHWND.NetUICtrlNotifySink.RICHEDIT60W print(rich_edit.WindowText()) 

A list of elements is printed:

 Control Identifiers: NetUIHWND - '' (L162, T378, R562, B957) ['', '1', 'NetUIHWND', '0'] child_window(class_name="NetUIHWND") | | NetUICtrlNotifySink - '' (L186, T408, R537, B425) | ['2', 'NetUICtrlNotifySink1', 'NetUICtrlNotifySink', 'NetUICtrlNotifySink0'] | child_window(class_name="NetUICtrlNotifySink") | | | | RICHEDIT60W - '///' (L186, T408, R537, B425) | | ['RICHEDIT60W0', '///RICHEDIT60W', 'RICHEDIT60W1', '///', 'RICHEDIT60W'] | | child_window(title="///", class_name="RICHEDIT60W") | | RICHEDIT60W - '///' (L186, T408, R537, B425) | ['RICHEDIT60W0', '///RICHEDIT60W', 'RICHEDIT60W1', '///', 'RICHEDIT60W'] | child_window(title="///", class_name="RICHEDIT60W") | | NetUICtrlNotifySink - '' (L184, T548, R515, B562) | ['3', 'NetUICtrlNotifySink2'] | child_window(class_name="NetUICtrlNotifySink") | | | | RICHEDIT60W - 'qwerty' (L184, T548, R515, B562) | | ['RICHEDIT60W2', 'qwerty', 'qwertyRICHEDIT60W'] | | child_window(title="qwerty", class_name="RICHEDIT60W") | | RICHEDIT60W - 'qwerty' (L184, T548, R515, B562) | ['RICHEDIT60W2', 'qwerty', 'qwertyRICHEDIT60W'] | child_window(title="qwerty", class_name="RICHEDIT60W") | | NetUICtrlNotifySink - '' (L162, T378, R162, B378) | ['4', 'NetUICtrlNotifySink3'] | child_window(class_name="NetUICtrlNotifySink") qwerty 

enter image description here

As you can see from the list of elements, the first one was to be "///", not "qwerty". What is the problem? How to get an item with "///"?

    1 answer 1

    It turned out to do this:

     import pywinauto window = pywinauto.findwindows.find_element(title_re='Microsoft Lync.*') child = window.children()[3] print(child.rich_text) # ///