sikuli if exists or if not exists

Asked by Nermin Doğanlı

Hi,
I made a sikuli ide script for one of the social media exchange site.
My script is running perfectly what i want until a image not found. When that image not found,i want to pass this image to related next one and the script should be keep to running. Here is my code and i'll explain through it.

while True:
    wait(4)
    doubleClick("1491684759044.png")
    waitVanish("1491686155624.png", 7)
    click("1491686205379.png")
    wait("1491686653455.png", 10)
    click("1491686741150.png") # if exists continue to statement, if not exists click ("1491686890829.png")
    wait (4)
    click("1491686890829.png")
    wait (4)

I hope i could explain.
Thanks.

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
Milteven (milteven12) said :
#1

I'm a python/sikuli "newbie" but here is what I think of a solution:

Just put your code inside a if/else statement,so:

while True:
[YOUR CODE]

#if existis continue to statement
#if not exists, it will fall into a else

else:
click("img")

Revision history for this message
Nermin Doğanlı (nermindoganli) said :
#2

Hi @Milteven,
thanks for your advice.So should it be like this ;

while True:
    doubleClick("1491684759044.png")
    waitVanish("1491686155624.png", 7)
    click("1491686205379.png")
    wait("1491788308581.png", 10)
    click(Pattern("1491788308581.png").targetOffset(-47,-1))
    wait (4)
    click("1491686890829.png")
    wait (4)
else:
    click("1491686890829.png")

       if it should be like this,still it is not clicking to;
else:
    click("1491686890829.png")

Revision history for this message
Vishal (vm5feb) said :
#3

You may try

if not exists("1491815558681.png",50):
    print "pass"
else:
    click("1491815558681.png")

Revision history for this message
Milteven (milteven12) said :
#4

Probably it is not working because there is no "if" before the else statemente, try to add it inside the while and use a variable to pass the if, like:

while True:
   variable_one = True
   if variable = True
      YOUR CODE
    else:
      click("1491686890829.png")

The goal is to while your condition is true, it will proceed to the if, that will be true just if variable_one = True, if it is true, your code will be executed, if not, it will fall into the else, and will click on the img.

PS: I do not tested the code.

Revision history for this message
Nermin Doğanlı (nermindoganli) said :
#5

Hi,
First of all thank you for advices.I solved the problem with following below;

 if exists(Pattern("1491794629239.png").targetOffset(-1,2), 7):
        click(Pattern("1491794629239.png").targetOffset(-1,2))
    else: click("1491686890829.png")

As I do not know why if i use ;

else:
   click("1491686890829.png") # with tab it is not working!

else: click("1491686890829.png") # like this working like a charm :D

Thank you very much who advice me. Cheers <3

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

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