Skip to content

Commit 2ddc686

Browse files
committed
Enhance error message when filtering UIPath with regex and index with regex and index.
1 parent 42072f7 commit 2ddc686

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pywinauto_recorder/player.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class FailedSearch(PywinautoRecorderException):
5151
'drag_and_drop', 'middle_drag_and_drop', 'right_drag_and_drop', 'menu_click',
5252
'mouse_wheel', 'send_keys', 'set_combobox', 'set_text', 'exists', 'select_file', 'playback',
5353
'find_cache_clear', 'UIApplication', 'start_application', 'connect_application', 'focus_on_application',
54-
'find_main_windows', 'kill_application']
54+
'find_main_windows', 'kill_application', 'FailedSearch']
5555

5656

5757
# TODO special_char_array in core for recorder.py and player.py (check when to call escape & unescape)
@@ -351,9 +351,18 @@ def _find(
351351
else:
352352
full_smart_element_path = UIPath.get_full_path(y_x[0])
353353
ref_unique_element = find_elements(full_smart_element_path)
354-
if len(ref_unique_element) > 1:
355-
msg = "No element found with the UIPath '" + full_smart_element_path + "' in the array line."
356-
raise FailedSearch(msg)
354+
if len(ref_unique_element) != 1:
355+
msg = f"While searching for the UIPath '{full_element_path}' :\n"
356+
if len(ref_unique_element) == 0:
357+
msg += f"No element found with the UIPath '{full_smart_element_path}'."
358+
raise FailedSearch(msg)
359+
elif len(ref_unique_element) > 12:
360+
msg += f"{len(ref_unique_element)} elements found with the UIPath '{full_smart_element_path}'."
361+
raise FailedSearch(msg)
362+
else:
363+
elements_list = "\n".join(elem.element_info.name + '||' + elem.element_info.control_type for elem in ref_unique_element)
364+
msg += f"{len(ref_unique_element) } elements found with the UIPath '{full_smart_element_path}': \n{elements_list}"
365+
raise FailedSearch(msg)
357366
ref_r = ref_unique_element[0].rectangle()
358367
r_y = 0
359368
while r_y < nb_y:

0 commit comments

Comments
 (0)