I did manage with these functions as workaround. The firs retrieve the window handle based on title, and the second retrieve the handle by the class name. This second approach can be used to find the context menu. Also this class can be used with Robot framework.
import win32gui
class AppTopLevelWindowFinder:
def find_window_handler_by_title(self, name):
windows = []
win32gui.EnumWindows(enumHandler, windows)
for next_window in windows:
if name in next_window[0]:
return next_window[2]
def find_window_handler_by_class(self, classname):
windows = []
win32gui.EnumWindows(enumHandler, windows)
for next_window in windows:
if classname in next_window[1]:
return next_window[2]
def enumHandler(hwnd, lwindow):
if win32gui.IsWindowVisible(hwnd):
lwindow.append((win32gui.GetWindowText(hwnd), win32gui.GetClassName(hwnd), hex(hwnd)))
newobj = AppTopLevelWindowFinder()
print(newobj.find_window_handler_by_title('Incoming Call'))
print(newobj.find_window_handler_by_class('32768'))