Search code examples
pythonpython-3.xwindowspywinauto

To extract the title name using pywinauto


I recently started using pywinauto. I am trying to fetch the title of the pop-up window.

FYI Application background is UIA.

enter image description here

In the above picture, the title of the pop-up window is "Open Media". Is there any way to extract/read this title using pywinauto.

So I am curious that is it possible to find the title of the pop-up window using pywinauto.


Solution

  • You can have the title of the popup window with the following Pywinauto code:

    desktop = pywinauto.Desktop(backend="uia")
    window = desktop.windows(title="VLC media player", control_type="Window")[0]
    wrapper_list = window.descendants(control_type="Window")
    for wrapper in wrapper_list:
        print(wrapper.window_text())
    

    The result is: 'Open Media'

    You can find it with an inspect tool like "Inspect.exe". You can easily find it with "Pywinauto recorder"

    With "Pywinauto recorder" if you hover the pop-up window with the mouse cursor and press CTRL+SHIFT+F it copies the following Python code into the clipboard:

    with UIPath(u"VLC media player||Window"):
        wrapper = find(u"Open Media||Window")
    

    Then if you add the next line, you will have the same result as with the pure Pywinauto code above.

    print(wrapper.window_text())
    

    Finally you have:

    with UIPath(u"VLC media player||Window"):
        window = find()
    wrapper_list = window.descendants(control_type="Window")
    for wrapper in wrapper_list:
        print(wrapper.window_text())