Is there way in sikuli to wait for an element until its visible ? ? ?

Asked by Kogul

I would like to know, is there any way to wait for an element until the element is visible. In selenium, there is a concept called Explicit wait. In that concept, the user won't give the input's like seconds, minutes, hours to wait for an element. It automatically searches for a particular element. I like to know is there is any way without entering the wait time, the wait should be automatically elongated until the element or text is visible.

Please find the below example in which I'm getting struck:

if(screen.exists("statusCompleted.png",3600)!=null){
System.out.println("project created successful");
}

else if(screen.exists("failed.png",3600)!=null){
System.out.println("project created was unsuccessful");
}

From the above code, the problem here am facing here is, If the test run fails, the control doesn't come to the else if part, first if the part is getting waiting/searching for a status-completed image for 3600 sec and then the control comes to else if.

My expectation is if the status-completed is not seen on the screen, the next second the control should come to the else if part. Is there any solution or workaround for this scenario? Please help.

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

If you want to determine whether image A or image B exists at that moment
imagelist = [imageA, imageB]
mm = findAny(imagelist)
for m in mm:
    print m.getIndex()

https://sikulix-2014.readthedocs.io/en/latest/region.html#findmorethanoneimage

If you want to check in sequence at that moment
if exists(imageA, 0):
    print "imageA is found"
elif exists(imageB, 0):
    print "imageB is found"

If you want to check continuously for 3600 seconds
t = 3600
while t > 0:
if exists(imageA, 0):
    print "imageA is found"
elif exists(imageB, 0):
    print "imageB is found"
wait(10)
t = t - 10

Revision history for this message
Kogul (selvanathan4220) said :
#2

Can you please write it in java? Am using sikuli api in eclipse, using
java as a programming language

On Thu, 22 Oct, 2020, 11:05 pm masuo, <email address hidden>
wrote:

> Your question #693582 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/693582
>
> Status: Open => Answered
>
> masuo proposed the following answer:
> If you want to determine whether image A or image B exists at that moment
> imagelist = [imageA, imageB]
> mm = findAny(imagelist)
> for m in mm:
> print m.getIndex()
>
>
> https://sikulix-2014.readthedocs.io/en/latest/region.html#findmorethanoneimage
>
> If you want to check in sequence at that moment
> if exists(imageA, 0):
> print "imageA is found"
> elif exists(imageB, 0):
> print "imageB is found"
>
>
> If you want to check continuously for 3600 seconds
> t = 3600
> while t > 0:
> if exists(imageA, 0):
> print "imageA is found"
> elif exists(imageB, 0):
> print "imageB is found"
> wait(10)
> t = t - 10
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/693582/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/693582
>
> You received this question notification because you asked the question.
>

Revision history for this message
masuo (masuo-ohara) said :
#3
Revision history for this message
Kogul (selvanathan4220) said :
#4

Thanks for the reply, but it did not solve my problem. The script should dynamically wait for a text, as soon as the text visible on the screen, the control should change to if or else if, that's my concern. If I use the above code first it waits for 3600 seconds and checking the else if condition.

Revision history for this message
masuo (masuo-ohara) said :
#5

if set zero to second parameter of "exists", "exists" return without wait.
#1 example "If you want to check in sequence at that moment"
#1 example "If you want to check continuously for 3600 seconds"

Revision history for this message
Kogul (selvanathan4220) said :
#6

Thanks for the reply, I like to give you a clear picture.

In my application, the text changes dynamically on the screen. the text I need to capture is Success and failure. If the application works, success text will appear on the screen/app, if the application crashed, failure text will appear on the screen/app. The challenge here am facing is I need to wait for the (Success/Failure) text to capture and write the steps in the log. The challenge here is I'm not sure about the exact time for the text to appear on the screen/app. Either Success or failure text will appear on the screen so I used the below code using the If condition.

if(screen.exists("statusCompleted.png",3600)!=null){
System.out.println("project created successful");
}

else if(screen.exists("failed.png",3600)!=null){
System.out.println("project created was unsuccessful");
}

The issue here I faced is if the application succeeds, the Sikuli is waiting until the (success )text is visible & entered into the if condition and I can print the System.out.println("project created successfully"); but if the application crashed the control remains in the If condition and waiting for 3600 seconds and the control not moving to else if part. I don't need to be a wait if the text is not present on the screen.

I need a solution to break this barrier. my concern is as soon as the image is not present in if condition, the control should change to else condition

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

Boolean success = null;
for (int n=0; n < 3600; n++) {
  if (screen.exists("failed.png", 0)) {success = false; break}
  if (screen.exists("statusCompleted.png", 0)) {success = true; break};
  wait(1.0);

if (success != null) {
  //either success or failed
} else {
  // neither image appeared after > 3600 seconds
}

Revision history for this message
Kogul (selvanathan4220) said :
#8

Hi Railman,

Thanks for the reply and solution. I will implement the above solution get
back here if there is any hurdle in the implementation.

On Fri, Oct 23, 2020 at 4:15 PM RaiMan <email address hidden>
wrote:

> Your question #693582 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/693582
>
> Status: Open => Answered
>
> RaiMan proposed the following answer:
> Boolean success = null;
> for (int n=0; n < 3600; n++) {
> if (screen.exists("failed.png", 0)) {success = false; break}
> if (screen.exists("statusCompleted.png", 0)) {success = true; break};
> wait(1.0);
>
> if (success != null) {
> //either success or failed
> } else {
> // neither image appeared after > 3600 seconds
> }
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/693582/+confirm?answer_id=6
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/693582
>
> You received this question notification because you asked the question.
>

Revision history for this message
Launchpad Janitor (janitor) said :
#9

This question was expired because it remained in the 'Open' state without activity for the last 15 days.