StaleElementReferenceException on Python Selenium

后端 未结 9 2114
孤独总比滥情好
孤独总比滥情好 2020-11-27 13:28

I am getting the following error while using Selenium in python:

selenium.common.exceptions.StaleElementReferenceException: Message: u\'stale element referen         


        
9条回答
  •  一整个雨季
    2020-11-27 14:05

    >>>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

提交回复
热议问题