---Advertisement---

Sikuli Integration with Selenium WebDriver: Handle Windows Popups Using Image Recognition Best 2025

By Manisha

Updated On:

---Advertisement---
Sikuli Integration with Selenium

👉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

  1. What is Sikuli in Selenium?
  2. How to Integrate Sikuli with Selenium WebDriver
  3. Commonly Used Sikuli Classes and Methods
    • Screen Class
    • Pattern Class
  4. File Upload Example using Sikuli and Selenium
  5. Output Analysis
  6. Pros and Cons of Using Sikuli
  7. 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

  1. Download Sikuli JAR File
    Sikuli JAR from Maven
  2. Create Java Project in Eclipse
  3. Add Sikuli JAR to Build Path
    • Right-click the project → Build Path → Configure Build Path
    • Add Sikuli JAR along with Selenium JAR files

👉 Important Classes in Sikuli

Sikuli Integration with Selenium: The Screen class provides all the necessary methods for image-based interactions.

MethodDescriptionSyntax
click()Clicks the element in the images.click(“image.png”)
doubleClick()Double-clicks the elements.doubleClick(“image.png”)
type()Types text into the input fields.type(“image.png”, “Text”)
hover()Moves cursor over the images.hover(“image.png”)
find()Searches for the element on the screens.find(“image.png”)

👉Pattern Class (For Advanced Image Matching)

Sikuli Integration with Selenium: The Pattern class allows specifying image attributes like path and similarity.

MethodDescriptionSyntax
getFileName()Returns file name of the imagep.getFileName()
similar()Matches image with a similarity value (0 to 1)Pattern p = p.similar(0.7f)
exact()Finds only an exact image matchPattern 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.

  1. Set Chrome Driver Path
  2. Capture Screenshots of ‘Choose File’ Textbox and ‘Open’ Button
    • Save as FileTextBox.PNG and OpenButton.PNG
  3. Initialize Screen and Pattern Classes
  4. Launch URL and Click Choose File Button
  5. Wait for Windows Popup
  6. Type File Path and Click Open
  7. Close Browser

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?

  • Windows file upload dialogs
  • Automating non-DOM elements like flash, videos
  • Desktop applications automation
  • 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.

Testing Selenium Download

 Scroll a Web Page in Selenium 

Leave a Comment

Index