# Differentiate identical buttons

Asked by Akos Kovacs on 2018-12-18

Buttons are the same.
I found findAll(path-to-imagefile[, similarity]) method as a possible solution, but not sure, how to get a predefined one, like second occurrence.

## Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2019-01-15
Last query:
2019-01-15
2019-01-08
 RaiMan (raimund-hocke) said on 2018-12-18: #1

 TestMechanic (ndinev) said on 2019-01-02: #2

There are many ways to solve this challenge. First of all buttons looks the same but have different coordinates .x and .y. So you can just compare coordinates and see left-right top-down order.

 Akos Kovacs (plaidshirtakos) said on 2019-01-08: #3

@TestMechanic: I try to use findAll() and getLastMatch() methods, but not sure, how to define Region.

setX(number)
setY(number)
setW(number)
setH(number)

 Akos Kovacs (plaidshirtakos) said on 2019-01-08: #4

Code, that I try:

Region reg = new Region();
reg.selectRegion()

reg.findAll("<myimg.png>")
click(reg.getLastMatch())

 RaiMan (raimund-hocke) said on 2019-01-08: #5

findAll() fills Lastmatches in the region, hence
must be:
reg.getLastMatches()

... but again: that is all in the docs

 TestMechanic (ndinev) said on 2019-01-08: #6

Here is ready for use method:

def GetImage_X_sort(img, n):
print ("Look X sorted elements like " + str(img) + " and take number " + str(n))
res=findAll(img)
sorted_img = sorted(res, key=lambda m:m.x)
sorted_img[n-1].highlight(2)
return sorted_img[n-1]

 Akos Kovacs (plaidshirtakos) said on 2019-01-15: #7

Thanks RaiMan, that solved my question.

 Akos Kovacs (plaidshirtakos) said on 2019-01-15: #8

@TestMechanic: Thanks for your help too, but your method produced some errors.