Pages

How to get rid of FindFailed Exception in SikuliX script using Selenium Webdriver!

SikuliX works on the principal of automating anything you see on the screen. It uses image recognition to access the web elements in a web page. One of its many advantages is that it can automate flash objects in the website.

One major hurdle you get in coding with SikuliX API in Selenium is the FindFailed exception. Whenever there is even the slightest mismatch between the image you are trying to find and the image on the screen, your script will abort throwing the FindFailed exception. Even though you will find both images perfectly matching but they differ in terms of RGB pixels and it's hard to tell for the naked eye. If your test case is not focused on GUI testing and you just want to access the web element using SikuliX script, this could be a tedious job to do. One very good suggested solution I found going through Sikuli docs is:
  1. Create a Pattern from the image
  2. Set the minimum Pattern similarity to be used to less than the default value of 0.7
  3. Create a Region on the screen where you exactly want to locate the element
  4. Finally look for the item in the newly created region instead of looking for it in the whole screen
Below I share a simple piece of code that 
  • Opens the Disney World website using Chrome browser.
  • Clicks on 'View Gallery'
  • Clicks through images using next.png below
next.png
I took this image using qSnap on Windows 10 Pro on default screen resolution of (3840 × 2160). Note that this image doesn't match the default pattern similarity level 0.7. This is perfect since we want to locate the next link using suggested solution above.
Although all of the above hustle of creating the perfect region with desired coordinates could be avoided using findElement function as below in the for the loop. I chose to find the next link using SikuliX for demonstration purposes.

No comments:

Post a Comment