← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #255812]: How to click in the right place among identical ones

 

Question #255812 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/255812

    Status: Open => Answered

Eugene S proposed the following answer:
Hi,

Definitely, picking a match out of multiple similar matches is a
challenge. There are some approaches that you might consider:

1. Use nearby object as a pivot.
So if you have any other object that you know its certain location in regards to the one you want to match, you can use one of the Region relative location functions. For example, if you have the text right of the object you can do something like that:

find(<textAsPattern>).left().find().find(<plusButton>).click()


2. Use physical relative location.
If you know that there are X pluses and the one you want is the second one from the top, you can create a list of all of them, calculate their order according to their Y axis value and then pick the correct one. For example:

def clickByYLocation(number):
    
    matches = []
    for match in findAll(<plusIcon>):
        matches.append(match)
    
    matchesSorted = sorted(matches, key=lambda x: x.getY())
    matchesSorted[number].click()


This function will find all "plus" icons on the screen, create a list based on their Y value and then click the correct one according to the parameter "number" passed to the function.


Cheers,
Eugene

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.