As per my understanding, you want to find an element in some page and if you couldn't find it then you need to refresh the page to retry finding it again. If this is your requirement, then you can do like this :
wait = WebDriverWait(driver, 30);
try:
quote = wait.until(EC.element_to_be_clickable((By.XPATH, '//h4[@class="quote-number ng-binding"]'))).text.split("#")[1]
except TimeoutException:
driver.refresh()
In the above code, the try block will throw 'TimeoutException' if the element is not found within the given time out. The except block will catch that exception and it matches then it will refresh the page.
The above code will do this activity only once. If you want to continue this process until you find an element then use the below code:
notFound = True
while notFound:
wait = WebDriverWait(driver, 30);
try:
quote = wait.until(EC.element_to_be_clickable((By.XPATH, '//h4[@class="quote-number ng-binding"]'))).text.split("#")[1]
notFound = False
except TimeoutException:
driver.refresh()
But the above solution is not recommended because if it doesn't find an element that it is looking for then the code will go to an infinity looping state. To avoid this, I recommend you use the FluentWait like below :
wait = WebDriverWait(driver, 60, poll_frequency=5, ignored_exceptions=[NoSuchElementException, StaleElementReferenceException]);
quote = wait.until(EC.element_to_be_clickable((By.XPATH, '//h4[@class="quote-number ng-binding"]'))).text.split("#")[1]
Which will search an element every 5 seconds by ignoring NoSuchElementException, StaleElementReferenceException exceptions upto 1 minute of time. I hope it helps...