简体   繁体   中英

how to click an image from the screen by using Sikuli with java when there are two exact identical images present in the screen

I have 2 exact same images (pattern, color, size ,everything is same) on the screen and in this case how do I click on Image 1 ?

Whenever I am using the s.click() function, Sikuli tries to click on Image 1 some times and sometimes on Image 2 .

I have tried Pattern and exists but they are also not working as expected.

Pattern imagePatternPath = new Pattern("Image.png").exact();
        screen.click(imagePatternPath);

I expect to click on Image 1 , but the actual output is sometime it clicks on Image 1 and sometimes on Image 2 .

If there are two absolutely similar patterns on the screen, there is no way for Sikuli to distinguish them without some help. You have few options to resolve this problem.

location on the screen

If the patterns appear in known areas on the screen, you can limit the search to the expected area and thus, avoid picking the wrong pattern.

search by proximity

If you have any other objects that appear only next to one of the patterns you are attempting to locate but not the other, you can use them as pivots.

Have a look into Sikuli code, especially into the Region class here. It exposes various options to modify the search area around found patterns. For example:

public Region grow(int range) {
    return grow(range, range);
  }

Try looking at the patch notes next time, they are very helpful. But here is what I would try:

 result = findAll("Image.png")

This will return a List which you can iterate through to click the item you wat so in this case you would click the first item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM