Skip to content

Commit

Permalink
Allow for retries also within the select-at convenience method
Browse files Browse the repository at this point in the history
The additional resilience of the `*_expect` methods can also be
used in the particular case of select-at using an image within a
dropdown menu in the case where the click might be unsuccessful
and the dropdown menu will not open as a result.

Use the opportunity to reset cursor location (important if it is
visible on the screen) in all these retry-capable cases.
  • Loading branch information
pevogam committed May 7, 2024
1 parent 305991a commit 50f11e2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions guibot/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ def click_expect(self, click_image_or_location, expect_target,
try:
return self.wait(expect_target, timeout)
except FindError as error:
self.hover(Location(0, 0))
if i == retries - 1:
raise error

Expand All @@ -772,6 +773,7 @@ def click_vanish(self, click_image_or_location, expect_target,
try:
return self.wait_vanish(expect_target, timeout)
except NotFindError as error:
self.hover(Location(0, 0))
if i == retries - 1:
raise error

Expand Down Expand Up @@ -1220,7 +1222,7 @@ def fill_at(self, anchor, text, dx, dy,

def select_at(self, anchor, image_or_index, dx, dy,
dw=0, dh=0, ret_flag=True,
mark_clicks=1):
mark_clicks=1, tries=3):
"""
Select an option at a dropdown list using either an integer index
or an option image if the order cannot be easily inferred.
Expand All @@ -1235,6 +1237,7 @@ def select_at(self, anchor, image_or_index, dx, dy,
:param int dh: height to add to the displacement for an image search area
:param bool ret_flag: whether to press Enter after selecting
:param int mark_clicks: 0, 1, 2, ... clicks to highlight previous text
:param int tries: retries if the dropdown menu doesn't open after the initial click
:returns: self
:rtype: :py:class:`Region`
Expand Down Expand Up @@ -1283,6 +1286,14 @@ def select_at(self, anchor, image_or_index, dx, dy,
ypos=int(loc.y - dh / 4),
width=dw, height=dh,
dc=self.dc_backend, cv=self.cv_backend)
dropdown_haystack.click(image_or_index)
try:
dropdown_haystack.click(image_or_index)
except FindError:
self.hover(Location(0, 0))
if tries == 1:
raise
logging.info("Opening the dropdown menu didn't work, retrying")
self.select_at(anchor, image_or_index, dx, dy, dw, dh,
mark_clicks=mark_clicks, tries=tries-1)

return self

0 comments on commit 50f11e2

Please sign in to comment.