Element not available. Cannot invoke click

I wanted to know if there is a way to make the code continue even without finding an element or image

Hi @brenoalencar1, welcome to our forum.
That is a great question. The find method returns an Element object so you can do the following constructions:

if self.find(...):
    print("Element was found")
else:
    print("Element was not found")

print("This code will run anyway")

Let me know if that helps. If not, please share a bit of the code you are building so we can provide a better suggestion.

from botcity.core import DesktopBot

class Bot(DesktopBot):
def action(self, execution=None):

if not self.find( “login”, matching=0.97, waiting_time=15000):
self.not_found(“login”)
self.click() # desktop image

If he doesn’t find the image in 15 seconds he stops the code! I wish he would continue

The issue here is that you are invoking the self.click() even if the image is not found and that causes an exception.

Try this instead:

if not self.find( “login”, matching=0.97, waiting_time=15000):
    self.not_found(“login”)
    print("skipping the click")
else:
    print("element was found, the bot will click")
    self.click() # desktop image
1 Like

this solved my problem, thanks!

1 Like

Muito, resolveu meu problema também

1 Like