exists() in or-case in java

Asked by emrah kara

Hello,
i am trying to have a solution in different cases. what i want ist that waiting for 40 secons, if photo 34 exists, should it be cliked in A if 35, on b. i
But it doesnt work correctly. when the Photo 34 exists, it will be cliked int A, but if photo 35 exists, it waits though 40 seconds to click.

if((screen.exists("fotos/34.png",40)!=null)||(screen.exists("fotos/35.png",40)!=null)){
   System.out.println("burada 1");
   if(screen.exists("fotos/34.png")!=null)
    screen.click("fotos/A.PNG");
   if(screen.exists("fotos/35.png")!= null)
    screen.click("fotos/b.PNG");
  }

Question information

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

expressions like x or y are evaluated left to right.

since the first exists() waits 40 seconds if 34 does not appear, this is obvious.

So you have to do something like this (forgive me if it is not correct Java syntax):

waittime = 40

while wait time > 0 {
     Match m34 = screen.exists("fotos/34.png",0)
     Match m35 = screen.exists("fotos/35.png",0)
     if not m34 and not m35 {
           waittime = waittime -1
           wait( (double) 1.0)
           continue}
     screen.click(m34)
     screen.click(m35)
}

This works in your sense, since we are using exists(image,0), which returns in any case after one search try and we are putting the wait int a counting loop.

     screen.click(m34)
     screen.click(m35)
works if always only one of them is visible (click(null) does just nothing ;-) - and is the same as yours

Revision history for this message
emrah kara (emrah-karakoc) said :
#2

thanks but i dont want to click on m34 or m35 again..
if it is m34, it sould click on A.png
if it is m35, it should click on b.png

when i work with match and have " screen.click(m34) screen.click(m35)" at the end, how can i let it click on some other photos? because it will click one of them which is not null ..

hoffentlich verstehst du was ich meine :)

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

--- hoffentlich verstehst du was ich meine :)
aber klaro ;-)

--- it should click on A.png ...
Sorry my fault (war lessen kann ist im Vorteil ;-)

something like:
if (m34 != null) screen.click("fotos/A.PNG");

Revision history for this message
emrah kara (emrah-karakoc) said :
#4

if(m34 != null)
    screen.click("fotos/A.PNG");
   if(m35!=null)
    screen.click("fotos/b.png");
   break;
i did it like that :)

thanks alot ;)
vielen lieben Dank :)

Revision history for this message
emrah kara (emrah-karakoc) said :
#5

Thanks RaiMan, that solved my question.