迭代Selenium / Python中的WebElement

绝对新手

我试图遍历Web元素列表,然后单击列表中的每个元素,但是在第一次单击后,我得到了StaleElementReferenceException据我了解,页面会刷新,并且元素的ID会“过时”。有解决方法吗?谢谢

elements = driver.find_elements_by_css_selector("span.name")
for element in range(len(elements)):
    elements[element].click()
亚历克斯·布鲁斯

如果在单击元素后仅更改了元素的id,则可以使用以下代码:

elements = driver.find_elements_by_css_selector("span.name")
for element in range(len(elements)):
    elements[element].click()
    elements = driver.find_elements_by_css_selector("span.name")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Selenium / Python TypeError:“ WebElement”对象不可迭代

如何在Python Selenium中获取WebElement的类名?

使用Python在Selenium WebDriver中获取WebElement的HTML源

使用Python在Selenium WebDriver中获取WebElement的HTML源

使用Python重写Selenium中的webElement的.click()方法

在 python ( selenium.webdriver.firefox.webelement ) 中查找 selenium 中的细分

在python中使用selenium迭代列表項

这个 python selenium 程序不迭代

Python Selenium内部for循环不迭代

如何使用 Selenium Python 迭代谷歌页面

Selenium - 在迭代元素中搜索元素

使用 Pything 访问 Selenium 中的 webelement 列表中的 webelement

如何在Python Webbot / Selenium中迭代子级Webelements?

Python / Selenium:在Xpath中插入一个迭代器

使用Selenium for Python迭代地从<table>中读取特定元素

如何使用 Python 高效迭代 Selenium Webdriver 中的表號?

如何使用Selenium和Python在突出显示的脚本中单击Webelement

Python Selenium-AttributeError:WebElement对象在textarea中没有属性sendKeys

Python Selenium WebElement元素-无效的语法

如何在python中导入Selenium WebElement

使用 selenium Python 循环遍历 webelement

如何使用Selenium检索WebElement的文本-Python

无法从 Webelement Selenium Python 打印文本

使用多个条件在Selenium中查找WebElement

如何检查Selenium中是否存在webelement?

Selenium (JS) 中 WebElement 的 getText() 失败

如何在Selenium WebElement中搜索?

Python:迭代从请求会话到Selenium的传输cookie

在使用 selenium 和 python 抓取数据时迭代点击