Calling to a Sikuli script from Python (Selenium) Calling to a Sikuli script from Python (Selenium) selenium selenium

Calling to a Sikuli script from Python (Selenium)


I ran into a similar issue, so I wrote a CPython module for Sikuli. The module is hosted on GitHub and available via pip install sikuli. It's able to access an included Sikuli jar using pyjnius, so you don't have to use Jython or even install Sikuli itself (although I'd recommend it for recording purposes). The module currently covers most of the simpler Sikuli functions, so it should cover a lot of use cases.

After installing, a simple from sikuli import * will get you started, but as a best practice, I'd suggest only importing the functions you want to use. This is particularly important for this module, because sikuli has a type function which overrides Python's own type function.


If your sikuli script is completely independent and you just want to run it for once and then have control back to your python script. Then you can create a batch file, which calls your sikuli script and call this batch file from your python script instead. Once the batch file is done running, it exits and returns the control back to your python script.

Sample Batch file:

@echo offcall C:\Sikuli\runIDE.cmd -r C:\Automation\Test1.sikuliexit

Code snippet to call Sikuli script from inside python:

import subprocessdef runSikuliScript(path):    filepath = path    p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)    stdout, stderr = p.communicate()    print "Done Running Sikuli"p = "C:\\Automation\\Test1\\test1.bat"runSikuliScript(p)// You can carry on writing your python code from here on


For calling Sikuli code from Selenium, my first choice would be TestAutomationEngr's suggestion of using Java, since Selenium and Sikuli both have native Java bindings.

Since you want to use Python, you should try running Selenium under Jython. It's important to remember that Sikuli is Jython, which is probably why you're not able to import it. (The other reason would be that you don't have it in Jython's module path.) I have not tried this myself, but there was a bug fixed last year in Selenium which indicates that it should be fine under Jython.

Note that if you call your Sikuli code directly from Jython, you need to add

from sikuli.Sikuli import *

to the top. This is because the Sikuli IDE implicitly adds that to all Sikuli code.

Finally, your last resort is to call Sikuli from the command line. There's an FAQ for that. You probably want the "without IDE" version, where you're calling Java and passing in the sikuli-script JAR file.