Selenium - 循环遍历嵌套的 div - 过时的元素引用

时间:2021-06-01 19:31:11

标签: python html selenium selenium-webdriver xpath

蟒蛇

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

行对象很好。

columns:收集一行中的所有嵌套(双和三)div,其中 20 个由。所以它正在收集带有错误消息的 div:stale element reference: element is not attach to the page document。页面上实际上没有任何变化。注意:Pycharm 显示,columns,是一个 len 20 的列表。但是查看列表的每个对象/元素,它充满了这些错误。 https://i.imgur.com/vmBC388.png

根据[文档],该引用应该丢失(https://www.selenium.dev/exceptions/#stale_element_reference)。

我希望做这样的事情:

icon_counter = {"success":0, "failed":0, "pending":0}

if columns[17].find_element_by_class_name(icon_class_name):
   icon_counter["success"] += 1

.html

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

视觉:https://imgur.com/a/HIw4k3D#1MwfThg

0 个答案:

没有答案
相关问题