
👉Sikuli Integration with Selenium
Sikuli Integration with Selenium: Automating web elements is seamless with Selenium, but what about Windows-based popups or non-HTML elements? That’s where Sikuli comes in. Sikuli uses image recognition to automate GUI components by interacting with elements based on screenshots.
In this tutorial, you’ll learn how to integrate Sikuli with Selenium WebDriver, how to handle file upload popups, and use image-based interactions effectively.
👉 Table of Contents
- What is Sikuli in Selenium?
- How to Integrate Sikuli with Selenium WebDriver
- Commonly Used Sikuli Classes and Methods
- Screen Class
- Pattern Class
- Screen Class
- File Upload Example using Sikuli and Selenium
- Output Analysis
- Pros and Cons of Using Sikuli
- Conclusion
👉 What is Sikuli in Selenium?
Sikuli Integration with Selenium: Sikuli is an open-source GUI automation tool that uses image-based recognition to interact with elements on the screen. It can be used in conjunction with Selenium to handle:
- Windows file upload dialogs
- Flash objects
- Java applets
- Non-HTML elements
Sikuli Integration with Selenium: Unlike Selenium which relies on DOM-based locators, Sikuli identifies elements based on screenshots.
👉How to Integrate Sikuli with Selenium WebDriver
✅ Step-by-Step Setup:
- Download Sikuli JAR File
Sikuli JAR from Maven - Create Java Project in Eclipse
- Add Sikuli JAR to Build Path
- Right-click the project → Build Path → Configure Build Path
- Add Sikuli JAR along with Selenium JAR files
- Right-click the project → Build Path → Configure Build Path
👉 Important Classes in Sikuli
🖥️ Screen Class (Core for GUI Automation)
Sikuli Integration with Selenium: The Screen class provides all the necessary methods for image-based interactions.
Method | Description | Syntax |
click() | Clicks the element in the image | s.click(“image.png”) |
doubleClick() | Double-clicks the element | s.doubleClick(“image.png”) |
type() | Types text into the input field | s.type(“image.png”, “Text”) |
hover() | Moves cursor over the image | s.hover(“image.png”) |
find() | Searches for the element on the screen | s.find(“image.png”) |
👉Pattern Class (For Advanced Image Matching)
Sikuli Integration with Selenium: The Pattern class allows specifying image attributes like path and similarity.
Method | Description | Syntax |
getFileName() | Returns file name of the image | p.getFileName() |
similar() | Matches image with a similarity value (0 to 1) | Pattern p = p.similar(0.7f) |
exact() | Finds only an exact image match | Pattern p = p.exact() |
👉 Sikuli File Upload Example with Selenium
Sikuli Integration with Selenium: Let’s see how to use Sikuli to automate file uploads in a Selenium test case.
✅ Code Steps Overview:
- Set Chrome Driver Path
- Capture Screenshots of ‘Choose File’ Textbox and ‘Open’ Button
- Save as FileTextBox.PNG and OpenButton.PNG
- Save as FileTextBox.PNG and OpenButton.PNG
- Initialize Screen and Pattern Classes
- Launch URL and Click Choose File Button
- Wait for Windows Popup
- Type File Path and Click Open
- Close Browser
✅ Java Code Example:
java
System.setProperty(“webdriver.chrome.driver”, “path/to/chromedriver”);
WebDriver driver = new ChromeDriver();
driver.get(“https://demo-url.com/upload”);
driver.findElement(By.id(“uploadButton”)).click();
Screen screen = new Screen();
Pattern fileInput = new Pattern(“FileTextBox.PNG”);
Pattern openBtn = new Pattern(“OpenButton.PNG”);
screen.wait(fileInput, 10);
screen.type(fileInput, “C:\\Users\\User\\Documents\\samplefile.txt”);
screen.click(openBtn);
driver.quit();
👉 Output Analysis
- Launches Chrome and opens the demo file upload URL
- Clicks on ‘Choose File’ to trigger Windows popup
- Enters file path in the textbox and clicks ‘Open’
- Upload completes and browser is closed
⚠️ Note: Sikuli depends on image resolution. Make sure the test runs in the same screen resolution used while capturing images to avoid FindFailed exceptions.
👉When to Use Sikuli in Selenium?
✔ Ideal For:
- Windows file upload dialogs
- Automating non-DOM elements like flash, videos
- Desktop applications automation
❌ Not Recommended When:
- UI elements are dynamic or frequently changing
- Responsive applications with variable resolutions
- Test environment has inconsistent screen scaling
👉Conclusion
Sikuli is a powerful tool when combined with Selenium WebDriver for handling Windows popups and GUI components not accessible via DOM. However, it’s best used in controlled environments with fixed screen settings.
For more stable test automation, frameworks like AutoIT or Robot Framework are often preferred—but for quick and image-based automation, Sikuli still holds its place.