from selenium.common.exceptions import NoSuchElementException try: element=driver.find_element_by_partial_link_text("text") except NoSuchElementException: print("No element found")