Differentiate identical buttons

Asked by Akos Kovacs

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:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

... and again: please read the docs.

Revision history for this message
TestMechanic (ndinev) said :
#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.

Revision history for this message
Akos Kovacs (plaidshirtakos) said :
#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)

Revision history for this message
Akos Kovacs (plaidshirtakos) said :
#4

Code, that I try:

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

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

Revision history for this message
Best RaiMan (raimund-hocke) said :
#5

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

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

Revision history for this message
TestMechanic (ndinev) said :
#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]

Revision history for this message
Akos Kovacs (plaidshirtakos) said :
#7

Thanks RaiMan, that solved my question.

Revision history for this message
Akos Kovacs (plaidshirtakos) said :
#8

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