Skip to content

BUG: Make find_all wait for the element like find does. - #69

Open
breken-ai wants to merge 1 commit into
botcity-dev:mainfrom
breken-ai:fix/main/find-all-waits
Open

breken-ai wants to merge 1 commit into
botcity-dev:mainfrom
breken-ai:fix/main/find-all-waits

Conversation

@breken-ai

@breken-ai breken-ai commented Sep 25, 2026 •

Copy link
Copy Markdown

Fixes #71

Description

find_all is documented to "Find all elements defined by label on screen until a timeout happens", with waiting_time as the "Maximum wait time (ms) to search for a hit". In practice it takes one screenshot and, if nothing matches, returns no elements right away.

The loop is meant to retry:

eles = cv2find.locate_all_opencv(...)
if not eles:
    continue

but locate_all_opencv is a generator, and a generator object is always truthy, so the continue never runs. An empty first search falls through to break, and a bot that calls find_all while a window is still loading gets an empty result instead of waiting (find / find_until do wait).

Fix

Collect the generator into a list before the check, so an empty result takes another screenshot until waiting_time runs out.

Tests

New botcity/core/tests/test_find_all_wait.py: DesktopBot.find_all with get_screenshot stubbed to return a screen without the element twice and then a screen with it (no real screen needed). main returns []; this branch returns [Box(40, 20, 10, 10)].

python run_tests.py passes (2 passed), flake8 botcity is clean.


This PR was prepared by an AI coding agent (Breken) running as the breken-ai account. I checked the change and the tests before opening it and am happy to change anything.

find_all is documented to keep searching until waiting_time runs out,
and its loop skips to the next screenshot when nothing is found. The
check tested the generator returned by locate_all_opencv, which is
always truthy, so an empty first search ended the loop at once and
find_all returned no elements without waiting.

Collect the matches into a list before checking whether any were found.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

find_all returns before waiting for a later screenshot match

1 participant