UI Spy (Spy ++, SpyXX or analogs) can "browse" all the elements of the application. See the whole tree with the names of windows, handles, etc. Here is an example: 
How to get inside, knowing parental handles? How to get the names of nested windows, buttons and other entities. I want to implement a similar functionality, as in the screenshot above. I tried to get to the names of nested windows:
import win32gui parent_handle = 131588 child_handles = [] child_names = [] def all_ok(hwnd, param): child_handles.append(hwnd) child_names.append(win32gui.GetWindowText(hwnd)) win32gui.EnumChildWindows(parent_handle, all_ok, None) print(child_handles) print(child_names) But I get the error:
Traceback (most recent call last): File "C:/Users/ПК/PycharmProjects/TESTING/2.py", line 12, in <module> win32gui.EnumChildWindows(parent_handle, all_ok, None) pywintypes.error: (126, 'EnumChildWindows', 'Не найден указанный модуль.') Google did not help: (
Update. How to get the name of an element if it has a handle of the form 42 197570 2 2 18 (nested element, with spaces)?
Update 2. What's wrong. Let's figure it out. In the picture the main window: 
Indeed, handle = 65922.
import win32gui hwnd = 65922 print(win32gui.GetWindowText(hwnd)) Output: PureVPN - Secure Virtual Private Network Connection (Administrator)
But then we see a child window (a button with no name, but we must also somehow access it, in order to later get its child windows): 
import win32gui hwnd = 65922 # Parent window nIDDlgItem = 27151449 # Что здесь должно быть ? h = win32gui.GetDlgItem(hwnd, nIDDlgItem) print(h) All this ends with pain:
Traceback (most recent call last): File "C:/Users/ПК/PycharmProjects/TESTING/3.py", line 5, in <module> h = win32gui.GetDlgItem(hwnd, nIDDlgItem) pywintypes.error: (1421, 'GetDlgItem', 'Не найден идентификатор элемента управления.')
2.pyfor example inС:/, and execute there? - megaIDchild window indicated by a space. The handle of such a child window can be obtained via a call to GetDlgItem . Transfer the value after the space tohDlg, and the value before the space inhDlg- mega27151449- it may well be a handle to the child window, and2252- you have indicated above that this is aPID. - mega