I am getting the following error while using Selenium in python:
selenium.common.exceptions.StaleElementReferenceException: Message: u\'stale element referen
>>>Stale Exceptions can be handled using **StaleElementReferenceException** to continue the for loop execution.
from selenium.common import exceptions
# and customize your code of for loop as:
for i in range(0, 22):
try:
u = driver.find_elements_by_id("data")
text = u[0].get_attribute("innerHTML")
driver.find_elements_by_class_name("aclassname")[0].click()
except exceptions.StaleElementReferenceException,e:
print(e)
pass
Note: Python 3+ : replace exceptions.StaleElementReferenceException,e -> exceptions.StaleElementReferenceException as e