Search code examples
jythonsikulisikuli-ide

Sikuli jython function with Region as argument is not working


I've Sikuli script on jython, which purpose is to sequentialy wait to appear and click images.

According to Sikuli it can be done with wait and click functions. Both functions take same argument - image to wait and click.

I'm using Sikuly IDE where an image is referenced as a thumbnail. So, I've to use same thumbnail two times to achive my goal.

I've tried to create a function with image as argument:

def wcl(PSRML):
    wait(PSRML, 10)
    click(PSRML)   

wcl(<Region image here>)

enter image description here

But it doesnt work:

[error] script [ hs1 ] stopped with error in line 6
[error] java.lang.IllegalArgumentException ( java.lang.IllegalArgumentException: SikuliX: find, wait, exists: invalid parameter: R[2707,673 225x179]@S(0) )
[error] --- Traceback --- error source first
line: module ( function ) statement 
65: Sikuli (  wait )     return SCREEN.wait(target, timeout)
2: main (  wcl )     wait(PSRML, 10)
6: main (  <module> )     wcl(Region(2707,673,225,179))
[error] --- Traceback --- end --------------

What would be proper way to write this function?


Solution

  • This is RaiMan from SikuliX.

    Screenshots (you say thumbnail) are images to search for on the screen and are taken in the IDE using the left most toolbar button (Take Screenshot).

    So the simplest version for your wait and click is:

    click(screenshot)

    which waits 3 seconds (standard) for the image to appear and then clicks the middle of the match.

    If you need to wait longer for an image, then you can say:

    click(wait(screenshot, time)) # time in seconds

    This is the same as:

    wait(screenshot, time))
    click() # which clicks the last match
    

    So no need to have the same shot twice.

    In any case you get a FindFailed exception if the image is not found and your script stops.

    I recommend to at least read across the documentation for an idea abou features and possibilities (https://sikulix-2014.readthedocs.io/en/latest/index.html).