Search code examples
javatestingautomationsikuligui-testing

How to click on some image which occurs multiple times on screen with sikuli with java?


I am writing some script automation in java which searches some recordings for mobile number and finds multiple recording in gridview. Next to this I am trying to download all recordings by clicking download (multiple)button(s). I have written below code but does not work

public static Screen s = new Screen();
Iterator <Match> matches  =s.findAll("downloadbtn_wh.png"); // s is screen
Pattern pButton = new Pattern("downloadbtn_wh.png");

Match mButton;

while (matches.hasNext()) {
    Match m = matches.next(); // m now could be inspected with debugging
    s.click(m); // click on drop-down

    if ((mButton = s.exists(pButton))!=null) {
        // checks for button image and saves the match
        s.click(mButton); // just click the match, do not search again
        break;
    }
}

This script stops after clicking on first download button but I expect that it should click on every download button in gridview. Images


Solution

  • The below code will perform what you require.

    @Test
    public void multiplePattern() throws FindFailed{
    
        ImagePath.setBundlePath("C:\\patterns\\");
    
        Screen s = new Screen();
        Iterator<Match> it = s.findAll("downloadArrow.png");
    
        while(it.hasNext()){
    
            it.next().highlight(1);
        }
    }
    

    NOTE: Please note that in the above example I am not actually clicking but only highlighting the detected patterns just to visualize the process. Just replace highlight(1) with click() before you use it in your script.