Find a series of identical images and get the mouse coordinations of each

Hello everyone,
I need to find a series of IDENTICAL objects (2-4 objects), and get the mouse coordinates of each object from a list of variables.
After that, move the mouse to one of these variables obtained.

Ty all.

Hi @dimitriusss, welcome!

You can use the find_all method to search for all occurrences of the same element: Computer Vision - BotCity

With the returned elements, you could do something like this:

# Searching for all "element" occurrences
elements = self.find_all(label="element", matching=0.97, waiting_time=20000)

for ele in elements:
   print(ele) # Printing element coordinates
   self.mouse_move(ele.left, ele.top)

Hi @joaovoltarelli, ty for replying.

your code worked fine, now how do i move the mouse to just one of these objects? I thought of a list of variables so that I could direct the mouse to the necessary object

1 Like

Hey @dimitriusss

I used the for just to demonstrate that it is possible to go through all the elements that were found, but you can do it the way you thought too.

With the elements in hand, you can do basically any treatment needed to manipulate the desired element. For example, if you want to access the second occurrence of the element, you can do the following:

 # Converting to list
elements_list = list(elements)
# Getting the second element of the list
x = elements_list[1].left
y = elements_list[1].top
self.mouse_move(x, y)

Just a tip, in this example Iā€™m converting the return from find_all to a list. But if you are doing a web automation, you can pass the as_list=True parameter so that find_all will already return as a list.

1 Like