Find() function with two or more images - Função find() com duas ou mais imagens

Olá, boa tarde!

Gostaria de saber se existe a possibilidade de realizar a função find() em duas imagens sendo ela a mesma apenas com a cor diferente quando selecionada?

Teria um exemplo prático de como fazer?

Tentei fazer desse jeito abaixo mas não funcionou.

if not self.find( "bt_painel_presentes", matching=0.97, waiting_time=10000) or self.find( "bt_painel_presentes2", matching=0.97, waiting_time=10000):
self.not_found("bt_painel_presentes") or self.not_found("bt_painel_presentes2")
else:
self.click_relative(159, 56)

Desculpe a pergunta, sou novo em programação e ainda estou aprendendo.

Imagem de exemplo:
IMG_3

-------- Edit to add english version and to format code --------

Hi, good afternoon!

I would like to know if it is possible to use the find() function with two images which are the same except for the color when selected?

Do you have an example of how to do it?

I tried to do it with the code below but it didn’t work.

if not self.find( "bt_painel_presentes", matching=0.97, waiting_time=10000) or self.find( "bt_painel_presentes2", matching=0.97, waiting_time=10000):
self.not_found("bt_painel_presentes") or self.not_found("bt_painel_presentes2")
else:
self.click_relative(159, 56)

Sorry for the question but I am getting started with programming and I am still learning.

Example image:
IMG_3

Olá @marcelbrn, bem-vindo!
Como este fórum é da comunidade global pedimos que os posts e mensagens trocadas em público sejam em inglês.
Editei seu post para adicionar uma versão em ingles tambem.

Vamos a resposta pra sua dúvida:

Você pode fazer uma construção da seguinte forma:

if self.find( "bt_painel_presentes", matching=0.97, waiting_time=10000) or self.find( "bt_painel_presentes2", matching=0.97, waiting_time=10000):
    self.click_relative(159, 56)

Explicando o código:

  • Se o recorte bt_painel_presentes seja encontrado OU o recorte bt_painel_presentes2 for encontrado
  • Faça o clique relativo

----- English Version -----

Hi marcelbrn, welcome!
As this is a global community forum we ask that all posts and public messages to be in english.
I edited your post to add an english version.

Let’s get to your question:

You can use the following construction:

if self.find( "bt_painel_presentes", matching=0.97, waiting_time=10000) or self.find( "bt_painel_presentes2", matching=0.97, waiting_time=10000):
    self.click_relative(159, 56)

Explaining the code:

  • If the bt_painel_presentes image is found OR the bt_painel_presentes2 is found
  • Click relative

Hi hslepicka,

I implemented it this way and it didn’t work.

Element not found: bt_bau_bonus
Element not found: bt_bau_bonus2

Could you do this using the find_all() function, if so would you be able to leave a practical example?

@marcelbrn could you paste here part of the code?

The way that the highlighted area is written it will print the message under the following conditions:

  • if bt_bau_bonus was NOT found
  • if bt_bau_bonus2 was found

The not is negating your first find only, not the whole condition.

To achieve what you want, you need to put your two conditions in parenthesis like this:

if not (self.find("bt_bau_bonus", ...) or self.find("bt_bau_bonus2", ...)):
    # This code will execute if none of the buttons are available
    self.not_found("bt_bau_bonus")
    self.not_found("bt_bau_bonus2")
else:
    # This code will be executed if at least one of the buttons is available.
    ...

Let me know if this works for you.

1 Like

Solved slepicka, that one was easy. hahaha
Thank you very much!

1 Like