Sikuli Check multiple of the same images on screen

11,641

Solution 1

You can use findAll method from Sikuli Region class. The example code will look like this:

def returnImageCount(image):
    count = 0
    for i in findAll(image):
        count += 1
    return count

imageCount = returnImageCount(image)

if imageCount == 1:
    click(buttonX.image)
elif imageCount == 2:
    click(buttonY.image)
else:
    pass

Solution 2

To check all the occurrences of an Image on the screen use the below, additional click is added to get the confirmation of the image exact location.

code:

Screen s = new Screen();
Iterator<Match> it = s.findAll(Imagepath);

while(it.hasNext()){
    System.out.println("the match is "+it.next().click());
}

Or you can find the length of the iterator.

Solution 3

You can also use Python's list comprehension to do it:

imageCount = len(list([x for x in findAll(image)]))

#the rest is like @Eugene's answer
if imageCount == 1:
    click(buttonA)
elif imageCount == 2:
    click(buttonB)
else:
    pass
Share:
11,641
Admin
Author by

Admin

Updated on November 25, 2022

Comments

  • Admin
    Admin over 1 year

    I can check if the image exist with exists()

    But i want to know if i can check if the same image appears more than once appearing on the screen, for example:

    if a ball exists once click a button...

    if a ball exists twice on screen click another button... any ideas?