Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #71
Description
find_allis documented to "Find all elements defined by label on screen until a timeout happens", withwaiting_timeas 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:
but
locate_all_opencvis a generator, and a generator object is always truthy, so thecontinuenever runs. An empty first search falls through tobreak, and a bot that callsfind_allwhile a window is still loading gets an empty result instead of waiting (find/find_untildo wait).Fix
Collect the generator into a list before the check, so an empty result takes another screenshot until
waiting_timeruns out.Tests
New
botcity/core/tests/test_find_all_wait.py:DesktopBot.find_allwithget_screenshotstubbed to return a screen without the element twice and then a screen with it (no real screen needed).mainreturns[]; this branch returns[Box(40, 20, 10, 10)].python run_tests.pypasses (2 passed),flake8 botcityis clean.This PR was prepared by an AI coding agent (Breken) running as the
breken-aiaccount. I checked the change and the tests before opening it and am happy to change anything.