How can Sikuli be used to wait for a button for a long time, with perhaps some maintenance task in between?

43,037

Solution 1

Some other thoughts for you...

 while(1):
 wait(Button, 30*60) # This will spinlock for 30 minutes for the button to appear
 if exists(Button):
     hover(Button) # Debug statement allowing user to see what Sikuli has matched to
     click (Button)
 else:
     mouseMove(Location(50,100))
     mouseMove(Location(50,200))

Links:

Solution 2

Maybe Sikuli recognizes something that looks quite your button, and tries to click it. If you right click in the IDE your button pattern, you can fine tune the tolerance level for recognition. Try to cut the image exactly around your button and increase the value to be more precise.

I suggest you to read this tutorial
http://doc.sikuli.org/tutorials/surveillance/surveillance.html
and to set up a event handler to manage your button when it appears
http://doc.sikuli.org/region.html#Region.onAppear
http://doc.sikuli.org/region.html#observingvisualeventsinaregion
It is not much code to write.

You can get a nice example with full source code in Sikuli's Blog here http://sikuli.org/blog/2011/08/15/sikuli-plays-angry-birds-on-google-games/

I think you can just set up your handlers and go with

observe(FOREVER)

Solution 3

If you want sikuli to do stuff while your waiting for an image i would use the onAppear(pic, function) and observe(FOREVER, true) methods this is how it works

event = Sikuli.event

def function(event):
    click(yourButton.png)

onAppear(picYourWaitingFor.png, function)
observe(FOREVER, true)

basically what this does is onAppear will continuously scan the screen for picYourWaitingFor.png. sikuli continues execution after words so it's scanning while its working. on the appearance of said pic it will jump to the function you put down as the second parameter of onAppear.

Share:
43,037
sakatc
Author by

sakatc

Updated on July 09, 2022

Comments

  • sakatc
    sakatc almost 2 years

    I have a webpage where I am waiting for a button to appear, and when it appears I would like to click it. The button is on a timer and may take as long as an hour to appear. Also, if the button takes longer than a certain length of time to appear, I'd like to move the mouse (otherwise the website will log me out automatically).

    So, to wait for a button to appear I devised this Sikuli script:

    button = "button.png"
    
    while(1):
        if exists(button):
            print("found it")
            click(button)
            break
        else:
            print("wait longer")
            wait(button,30*60)
            # do a regular task
    
    print "all done!"
    

    The above does not seem to be functional. If the button is on screen, the script will find it... However, if it has to wait it will simply time out quickly with a FindFailed exception (on the click() even though the button does not exist on screen). I considered writing a handler, but seems like overkill.

    What am I doing wrong and what is the best way to wait a long period for a visual event like this?