from selenium.common.exceptions import NoSuchElementException try: driver.find_element_by_xpath("//span") except NoSuchElementException: