I had an issue which I was able to resolve with explicit wait. My curiosity comes, what goes inside selenium webdriver that when I used implicitly wait
for 300 seconds, it did continue to give stale element reference, but explicit wait with timeout 77sec
it works without error.
my code is below
for i in range(len(x_indexes)):
x_indexes = wait.until(EC.visibility_of_all_elements_located((By.XPATH, '//div[@data-asin]')))#--here i added explicit wait
x_data_asin=x_indexes[i].get_attribute('data-asin')#on this line error stale ref was occuring
if x_data_asin!="":
#clicking to each item for getting iban values ->back page
a_href_element_of_index=x_block_of_index.find_element(By.XPATH,'.//h2/a')
a_href_element_of_index.click()
a_isbn_element=driver.find_element(By.XPATH,'//span[contains(text(),"ISBN")]')
x_isbn_element_parent=a_isbn_element.find_element(By.XPATH,'..')
print(x_isbn_element_parent.get_attribute('textContent'))
#driver.back()
driver.execute_script('window.history.go(-1)')
print(a_href_element_of_index,'a',sep='-->')
#driver.implicitly_wait(300)
--loop ends
when i loop each item inside x_indexes I click every anchor element, page directs to another page there i pull out data that i want, then driver.back
or driver.execute_script('window.history.go(-1)')
brings me back to the page where iteration continues in same way. I was having stale reference the element was not attached to page, I tried implicitly waiting till 300 after loop was ending line. The result was same error. So when I tried explicitly waiting wait=WebDriverWait(driver,timeout=77)
the error stopped occuring.
I wonder the logic behind waiting 300 seconds and 77 what lays behind in webdriver?