StaleElementReferenceException on Python Selenium

后端 未结 9 2136
孤独总比滥情好
孤独总比滥情好 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条回答
  •  猫巷女王i
    2020-11-27 13:52

    I Would like to add one more solution here which is worked for me.

    I was trying to access the button in the top menu panel on my webpage after refreshing the content area on the same page, Which gave me the following error,

        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of  is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
    

    Then I started to search for the solution to click the stale element on the web page. After two days of thinking and googling, I got a solution.

    To access the stale element on the page, first, we need to focus the mouse over the particular section and perform click option

    EditReport1 = driver.find_element_by_id('internalTab1')
    ActionChains(driver).move_to_element(EditReport1).click(EditReport1).perform()
    

    move_to_element will move the mouse over the stale element which we need to access once we got our control on the element the click operation is successfully performed.

    This is worked for me. If anyone finds it working please comment your's as well which will help some other in future.

    Thank you

提交回复
热议问题