from selenium.common.exceptions import NoSuchElementException def check_exists_by_xpath(xpath): try: webdriver.find_element_by_xpath(xpath) except NoSuchElementException: return False return True