Perform action on image when it appears dynamically without using sleep

Asked by ShrilekhaGowda

We have an application where the expected image will appear faster sometimes and delays sometimes(may take too long time or less)
I am using eclipse with java
Initially tried with thread.sleep(time) if the image appears faster execution is taking more time.
Pattern pattern = new Pattern("Image location");

screen.click(pattern);

Thread.sleep(60000);
//wait for next image to appear
Tried with below approaches but still not working
Approach1:
Screen screen = new Screen();
Pattern pattern1 = new Pattern("Image location ");
if(exists(pattern("C:\\1Winium\\Screenshots\\Capture2.png").exact(),3600));

Approach2:
screen.setAutoWaitTimeout(900000);
As soon as the image appears action is not performed but it is waiting again

Approach3:
while(screen.exists("Image location ") != null);
When the application will open it takes time for image to appear and hence this will fail.

Approach4:
screen.wait("Image location");
Again, this will say image not found since its tries to find image before it appears

Approach5:
screen.wait(pattern1,89000);
This is working similar to thread.sleep(89000)
I am new to sikuli Please help in finding a solution as soon as the image appears it should perform operation and should not wait till the time specified. Something like “explicit Wait” that we use in selenium. To avoid unnecessary delay while execution.
Referred below links:
https://answers.launchpad.net/sikuli/+faq/1607
https://answers.launchpad.net/sikuli/+question/657348
https://stackoverflow.com/questions/47887736/sikuli-ide-command-waitimage-not-waiting-for-image-to-appear-before-script-c
and referred few more .

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Generally: wait() and exists() internally repeat the search until the image is found or the standard (3 seconds) / given wait time is exceeded.

So the correct approach in your case:
wait(imageOrPattern, wait-time)
or
exists(imageOrPattern, wait-time)

The only difference between both:
- wait throws findFailed if not found within wait-time
- exits returns null if not found within wait-time

In any case all find methods return immediately, when the image is found.

So the wait-time in your case should simply be a value a bit larger than the largest delay you expect.

Revision history for this message
ShrilekhaGowda (lekha1995) said :
#2

@RaiMan
Thank you for the answer.
In my case i have used
wait(imageOrPattern, wait-time)
or
exists(imageOrPattern, wait-time)

Example: wait(imageOrPattern, 20seconds). image is appearing in 5seconds then the operation is not happening. it is waiting till complete 20seconds .

Revision history for this message
RaiMan (raimund-hocke) said :
#4

you say:

Example: wait(imageOrPattern, 20seconds). image is appearing in 5seconds then the operation is not happening. it is waiting till complete 20seconds .

I tested: this is not true.

in the moment the image appears in the region/screen, the wait-op is terminated instantly.

Can you help with this problem?

Provide an answer of your own, or ask ShrilekhaGowda for more information if necessary.

To post a message you must log in.