问题
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?
回答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
回答2:
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
回答3:
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.
回答4:
Use findall method of Region object. It gives you a list of all matching image/pattern. Sikuli documentation has good details on usage. Refer here http://doc.sikuli.org/region.html#Region.findAll
回答5:
If you would like to count the number of a certain image on the window you could use:
Image1 = ("Image1.png")
ImagesFound = list(findAll(Image1))
numberFound = len(ImagesFound)
print(numberFound)
And if you would like to count the number of a certain image on the most front window, like a pop-up.
You could use:
Image1 = ("Image1.png")
appWindow = App.focusedWindow()
ImagesFound = list(appWindow.findAll(Image1))
numberFound = len(ImagesFound)
print(numberFound)
来源:https://stackoverflow.com/questions/19614405/sikuli-check-multiple-of-the-same-images-on-screen