Python Selenium-通过嵌套的div-stale元素引用循环

Python Selenium-通过嵌套的div-stale元素引用循环,python,html,selenium,selenium-webdriver,xpath,Python,Html,Selenium,Selenium Webdriver,Xpath,蟒蛇 行对象是好的 列:收集一行中的所有嵌套(双重和三重)div,其中20个按。因此,它正在收集div,并显示一条错误消息:stale-element-reference:element未附加到页面文档。页面上实际上没有任何变化。注:Pycharm显示的列是len 20的列表。但是看看列表中的每个对象/元素,都充满了这些错误 根据[文档],该引用可能已丢失() 我希望做这样的事情: row = self.driver.find_element_by_class_name(CatalogP

蟒蛇

行对象是好的

列:收集一行中的所有嵌套(双重和三重)div,其中20个按。因此,它正在收集div,并显示一条错误消息:stale-element-reference:element未附加到页面文档。页面上实际上没有任何变化。注:Pycharm显示的列是len 20的列表。但是看看列表中的每个对象/元素,都充满了这些错误

根据[文档],该引用可能已丢失()

我希望做这样的事情:

    row = self.driver.find_element_by_class_name(CatalogPage.resultsTable_row_cssClass)
    columns = row.find_elements_by_xpath(".//div") ## this kind of works.
.html


064
回声、电影、上升

不适用

视觉:

我不明白
列[17]
是如何工作的。当您将
columns
定义为一个webelements数组时,
column
怎么可能是一个数组呢?您是对的,这是另一个代码段的输入错误。更正。问题是,列中满是20个项目(应该是这样),但它们都有过时的元素引用。在定义和使用
列的位置之间,必须导航到另一个页面,这就是导致过时元素引用的原因。@C.Peck nope。正是这样做的。加载页面、应用筛选器、定义行、定义列、尝试使用列。没有页面更改或任何事情。很高兴知道这种方法是正确的,将继续尝试当您对过时的webelement引用调用方法时,您将得到一个过时的元素异常。所以在您的例子中,它看起来像row.find_元素。。。调用正在抛出错误。(这意味着调用时DOM仍在更新。)要测试,请在获取行webelement引用之前添加良好睡眠。
icon_counter = {"success":0, "failed":0, "pending":0}

if columns[17].find_element_by_class_name(icon_class_name):
   icon_counter["success"] += 1
<div id="row-ac253ecd-8a8a-4b58-9a7a-fa2d2bcc619b" role="row" class="rdt_TableRow">
    <div id="cell-aanda" role="gridcell" data-tag="allowRowEvents" class="dkc rdt_TableCell"><div data-tag="allowRowEvents"><button type="button" class="ant-btn round-sm"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="1em" height="1em" fill="currentColor"><path d="m11.596 8.697-6.363 3.692c-.54.313-1.233-.066-1.233-.697V4.308c0-.63.692-1.01 1.233-.696l6.363 3.692a.802.802 0 0 1 0 1.393z"></path></svg></button></div></div>
    <div id="cell-cc19b" role="gridcell" data-tag="allowRowEvents" class="afk rdt_TableCell"><div data-tag="allowRowEvents"><div>064</div></div></div>
    <div id="cell-c619b" role="gridcell" data-tag="allowRowEvents" class="pka rdt_TableCell"><div data-tag="allowRowEvents">ECHO_CINEMATIC_RISE_STRESSMETALS</div></div>
    <div id="cell-qg69b" role="gridcell" data-tag="allowRowEvents" class="gla rdt_TableCell"><div data-tag="allowRowEvents"><div><p class="tag"></p></div></div></div>
    <div id="cell-c619b" role="gridcell" data-tag="allowRowEvents" class="awe rdt_TableCell"><div data-tag="allowRowEvents">N/A</div></div>
    <div id="cell-8ea1b" role="gridcell" data-tag="allowRowEvents" class="haw rdt_TableCell"><div data-tag="allowRowEvents"><div class="d-flex"><span class="bg-pending round-sm mx-1"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="1em" height="1em" fill="currentColor"><path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"></path></svg></span></div></div></div>
    <div id="cell-O619b" role="gridcell" data-tag="allowRowEvents" class="ara rdt_TableCell"><div data-tag="allowRowEvents"><button type="button" class="ant-btn bg-success round-sm mx-1 no-border"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="1em" height="1em" fill="currentColor"><path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"></path></svg></button></div></div>
    <div id="cell-V019b" role="gridcell" data-tag="allowRowEvents" class="dad rdt_TableCell"><div data-tag="allowRowEvents"><div class="d-flex"><a target="_blank" rel="noreferrer" href="/administration/tracks/ac253ecd-8a8a-4b58-9a7a-fa2d2bcc619b"><button type="button" class="ant-btn square-sm"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="1em" height="1em" fill="currentColor"><path d="M10.5 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0z"></path><path d="M0 8s3-5.5 8-5.5S16 8 16 8s-3 5.5-8 5.5S0 8 0 8zm8 3.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"></path></svg></button></a></div></div></div>
</div>