You can implement a try / except block as shown below to check if an element is present:
from selenium.common.exceptions import NoSuchElementException try: element=driver.find_element_by_partial_link_text("text") except NoSuchElementException: print("No element found")
or check the same with one of the find_elements_...() methods. It should return you an empty list or a list of elements matched using the passed selector, but not an exception if the elements are not found:
elements=driver.find_elements_by_partial_link_text("text") if not elements: print("No element found") else: element = elements[0]
source share