StaleElementReferenceException on Python Selenium

后端 未结 9 2115
孤独总比滥情好
孤独总比滥情好 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 13:40

    Beyond the answers here, if you are using ActionChains, and the page has changed, be sure to reinstantiate your ActionChains object (dont reuse an old one), otherwise your ActionChain will be using a stale DOM. I.e. do this;

    action_chain = ActionChains(driver)     
    action_chain.double_click(driver.find_element_by_xpath("//tr[2]/p")).perform()
    

    Or better yet dont use an instantiation;

    ActionChains(driver).double_click(driver.find_element_by_xpath("//tr[2]/p")).perform()
    

提交回复
热议问题