How to Create a Repeatable Loop

Asked by max

Hi, I just downloaded Sikuli 2 days ago. The Language and constructs are all very new to me, I am not familiar with programming code. But the potential of this type of program is great for me, if I can learn it. For now, I have a very simple question.

I have a program that runs overnight on my computer, but within the program the publisher has some unavoidable pop-ups that must be clicked to close or else the program is stagnant all night until I awake in the morning.

I attempted to make a Sikuli script to recognize a unique image within the pop-ups and then click to close the pop-up. The script works, but it only works for 1 occurrence. I want it to run continuously overnight to close the pop-ups as they appear several times during the night.

Here is the script I wrote
1) wait (image, FOREVER)
2) click (image)

Right now once it clicks to close the pop-up, the sikuli program stops.
I would like it to Wait until the Image appears
then to perform the function of clicking to close the pop-up
then to go back to waiting until the next time the pop-up appears
to perform the function of clicking to close again
repeat
repeat
and so on....

Question information

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

while True: # loop forever
    if exists(image, 0):
        click(some_image)
    wait(5)

this will look every 5 seconds and click if popup is there

Since this runs forever, it has to be stopped with the abort key or by killing the app manually.

If there is something on the screen while running, that identifies your main app, then this would stop automatically:

while True: # loop forever
    if not exists(imageMustBeThere, 0):
        break # end loop
    if exists(image, 0):
        click(some_image)
    wait(5)

or thinking positive ;-)

while True: # loop forever
    if exists(imageMustBeThere, 0):
        if exists(image, 0):
            click(some_image)
        wait(5)

Revision history for this message
max (max-vain) said :
#2

Thank you this works

while True: # loop forever
    if exists(image, 0):
        click(some_image)
    wait(5)

I will just open task manager and find the java process to manually abort when I want it to stop.

Thanks a bunch