I would like to extract the span text located within the class SOME_CLASS_NAME. The class SOME_CLASS_NAME might not always available. Also, it take some time before the class properly visible if it does exist.
To handle this, the following code were propsed.
Dirty workaround to check whether the class available or not
size_len = WebDriverWait(self.browser, 20).until(EC.presence_of_element_located(
(By.XPATH, './/span[@class = "SOME_CLASS_NAME"]')))
OR
if len( self.browser.find_elements_by_xpath('.//span[@class = "SOME_CLASS_NAME"]') ) > 0 :
element =self.browser.find_elements_by_xpath( './/span[@class = "SOME_CLASS_NAME"]' )[ 0 ].text
else:
element = '0'
While the above approach work, but,I found it very inefficient to evaluate the class for 3 times.
May I know if there is a way to make the above code more efficient?