Skip to content

Commit fd45e77

Browse files
committed
FIX: Make sure we return None when not found.
1 parent 699c618 commit fd45e77

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

botcity/web/bot.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,13 @@ def find_until(self, label, x=None, y=None, width=None, height=None, *,
402402
haystack = self.get_screen_image(region=region)
403403
it = cv2find.locate_all_opencv(element_path, haystack_image=haystack,
404404
region=region, confidence=matching, grayscale=grayscale)
405-
ele = next(it)
406-
if ele is not None:
407-
self.state.element = ele
408-
return ele
405+
try:
406+
ele = next(it)
407+
except StopIteration:
408+
ele = None
409+
410+
self.state.element = ele
411+
return ele
409412

410413
def find_text(self, label, x=None, y=None, width=None, height=None, *, threshold=None, matching=0.9,
411414
waiting_time=10000, best=True):
@@ -542,9 +545,16 @@ def get_element_coords(self, label, x=None, y=None, width=None, height=None, mat
542545
print('Warning: Ignoring best=False for now. It will be supported in the future.')
543546

544547
it = cv2find.locate_all_opencv(self.state.map_images[label], region=region, confidence=matching)
545-
ele = next(it)
546-
self.state.element = ele
547-
return ele.left, ele.top
548+
try:
549+
ele = next(it)
550+
except StopIteration:
551+
ele = None
552+
self.state.element = ele
553+
554+
if ele:
555+
return ele.left, ele.top
556+
else:
557+
return None, None
548558

549559
def get_element_coords_centered(self, label, x=None, y=None, width=None, height=None,
550560
matching=0.9, best=True):

0 commit comments

Comments
 (0)