I'm using Python and I came across one problem. I'm trying to make a bot using selenium, and it's coming along nicely but I'm trying to use a non-present element to activate a function and I just can't figure it out

if (element) not present:

I can't find anything on the internet.

1 Answer 1


You can either:

  • Look for all element that match certain search criteria:

    if driver.find_elements_by_css_selector(my_locator):
        # No element found here
  • Catch an exception when searching for a single instance:

       except NoSuchElementException:
           # No element found here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.