My work is use selenium.webdriver class to click the button in pages with python. If I am trying to find a element in page by xpath,sometimes the element may not exist.So before i use the element I should check whether the element exists or not. The most popular way to solve this question is to use try...expect statement. like this
def ElementExists(xpath):
try:
driver.find_element("xpath",xpath)
return True
except:
return False
It works well. But i find the time cost in try...expect statement is so long. It will cost almost 15 seconds, so what can we do to reduce the time cost with another way? Thanks