Skip to content

Commit

Permalink
Improving the robustness of menu_click
Browse files Browse the repository at this point in the history
  • Loading branch information
dpratmarty committed May 13, 2024
1 parent 1bc6e97 commit 0859778
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pywinauto_recorder/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ def distance(pt_1, pt_2):
duration = float(duration)/2

native_window_handle_before_menu = get_native_window_handle()
set_native_window_handle(None)
if absolute_path:
set_native_window_handle(None)
menu_entry_list = menu_path.split(path_separator)
str_menu_item = 'MenuItem~Absolute_UIPath' if absolute_path else 'MenuItem'
for i, menu_entry in enumerate(menu_entry_list):
Expand All @@ -821,6 +822,9 @@ def distance(pt_1, pt_2):
UIPath._path_list = UIPath._regex_list = []
mouse_cursor_pos = win32api_GetCursorPos()
ws = find_all('*' + path_separator + menu_entry + type_separator + str_menu_item, timeout=timeout)
if ws == []:
set_native_window_handle(None)
ws = find_all('*' + path_separator + menu_entry + type_separator + str_menu_item, timeout=timeout)
if ws == []:
time.sleep(1)
ws = find_all('*' + path_separator + menu_entry + type_separator + str_menu_item, timeout=timeout)
Expand All @@ -836,6 +840,7 @@ def distance(pt_1, pt_2):
time.sleep(0.1) # wait for the menu to open (it is not always instantaneous depending on the animation settings)
if i>0:
UIPath._path_list, UIPath._regex_list = SAV_UIPath_path_list, SAV_UIPath_regex_list
set_native_window_handle(None)
set_native_window_handle(native_window_handle_before_menu)
return w_to_return

Expand Down

0 comments on commit 0859778

Please sign in to comment.