当前位置: 动力学知识库 > 问答 > 编程问答 >

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

网友答案:

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.

网友答案:
Screen scn = new Screen();  
Iterator <Match> itr = scn.findAll("image");
{
    while(itr.hasNext())
    {
        itr.next().click();
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: