Python with Selenium “element is not attached to the page document”

前端 未结 2 801
难免孤独
难免孤独 2021-01-14 01:31

I have a python function that should click through all options of a product:

submit_button = driver.find_element_by_id(\'quantityactionbox\')

elementList =          


        
2条回答
  •  失恋的感觉
    2021-01-14 02:20

    You have the explanation and the solution on The Element is not Attached to the DOM:

    A common technique used for simulating a tabbed UI in a web app is to prepare DIVs for each tab, but only attach one at a time, storing the rest in variables. In this case, it's entirely possible that your code might have a reference to an element that is no longer attached to the DOM (that is, that has an ancestor which is "document.documentElement").

    If WebDriver throws a stale element exception in this case, even though the element still exists, the reference is lost. You should discard the current reference you hold and replace it, possibly by locating the element again once it is attached to the DOM.

提交回复
热议问题