So my code is working but I do not understand why and that annoys me.
def load_more():
while True:
try:
WebDriverWait(driver, 20, ignored_exceptions = (StaleElementReferenceException)).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".more"))).click()
time.sleep(1)
except TimeoutException:
return
The above function is used after I loaded the initial page to click a "show more" button until it is no longer there.
My frustration lies in the use of time.sleep(1)
. If I remove this the code throws a StaleElementReferenceException
at a random point. Even if it's listed in the ignored_exceptions
.
My question is. Why does the code require the use of the sleep()
function?