python - 在 python 中使用 selenium 迭代所有元素

标签 python selenium iterator web-scraping

我目前有一个脚本,可以使用链接文本“Toast”找到第一个元素

toast_link = driver.find_element_by_link_text('Toast')

我遇到的问题是链接文本“Toast”有多个实例,我想遍历所有这些实例。最好的方法是什么?

最佳答案

要查找多个元素,请使用 find_elements_* 而不是 find_element_*(注意:s):

toast_links = driver.find_elements_by_link_text('Toast')
for link in toast_links:
    ....

关于python - 在 python 中使用 selenium 迭代所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27878797/

相关文章:

c++ - 使用迭代器从双 for 循环构建 vector

python - Numpy 或 pandas : test whether upper or lower bound is reached in array/series, 哪个先到达

python - Scrapy xpath 删除 < 字符后的文本

python - pandas, numpy 四舍五入到最接近的 100

python - 网页 : How to serve JSON

python - 我可以在 python 中使用 selenium webdriver 滚动网页吗

exception - NetBeans:打开 -e 开关重新运行 Maven/PluginResolutionException

java - 使用 GeckoDriver 和 Firefox 执行代码时 org.openqa.selenium.firefox.NotConnectedException : Unable to connect to host 127. 0.0.1

c++ - 二进制搜索递减列表?

c - 为 BST 定义迭代器