waitFor
Being able to locate images on our screen is a huge benefit when automating things, but in reality, we have to deal with timing.
waitFor
is here to help by allowing us to specify a timeout in which we expect our template image to appear on screen!
Template images are Images
either directly loaded using their full path, or relative to a configurable resource directory.
See working with template images
for further info.
#
Waiting for imagesLet's tweak the snippet used on find just a little:
waitFor
basically does the exact same as find, but multiple times over a specified period of time.
It'll scan your main screen for the given template image, but if it fails to find it, it'll simply give it another shot. The interval in which these retries happen is configurable as well.
In the above snippet, we tell waitFor
to look for our template image for at most five seconds, retrying every second.
If it still couldn't locate the image after the configured timeout in milliseconds, it'll reject. Otherwise, it'll return the Region it located the image in, just like find.
#
TroubleshootingEverything mentioned on find applies to waitFor
as well.
#
TimeoutAction timed out after 5000 ms
#
SummarywaitFor
will repeatedly search your main screen for the template image and if it finds a match, it'll return the Region it located the template image in.- If it can't locate the image, it'll retry the search in configurable intervals until it hits the configured timeout in milliseconds.