I need to wait for the presence of an element with specific text in it. I want to fetch the info from that element in the moment the element is present and has text in it. I appears sometime after submitting a form and normaly fills with info a little later. My current solution looks like this:
wait = WebDriverWait(self.driver, MAXIMUM_LOAD_TIME)
try:
wait.until(ec.presence_of_element_located((By.ID,"IdOfElement")))
wait.until(ec.text_to_be_present_in_element((By.ID, "IdOfElement"), "theText"))
data = self._extract_data()
except TimeoutException:
raise WebsiteTimeoutError(MAXIMUM_LOAD_TIME)
This runs perfectly in >99% of the cases but now it happened that i got an error on ec.text_to_be_present_in_element.
The error was:
File "my/Path", line 436, in _scrape_quote
wait.until(ec.text_to_be_present_in_element((By.ID, "IdOfElement"), "theText"))
File "C:\Program Files (x86)\Python38-32\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
value = method(self._driver)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 210, in __call__
return self.text in element_text
TypeError: argument of type 'NoneType' is not iterable
Apparently the element dissapeared again. Is my assumption right? What is the best way to fix this?