首页 > 解决方案 > 如何使用 Python Selenium 找出网站中存在的特定元素?

问题描述

标签: pythonseleniumselenium-webdriverweb-scraping

解决方案


这将清楚地指示页面上是否有任何元素在其任何属性中包含“C10”。

elements = driver.find_elements_by_xpath("//*[contains(.,'C10')]")
if(elements):
    print("Elements containing C10 found on the page")

//*[contains(.,'C10')]将匹配任何属性中包含“C10”的任何元素。
driver.find_elements_by_xpath("//*[contains(.,'C10')]")将返回匹配的 Web 元素列表。如果找到这样的元素 - 列表将是非空的,非空列表被解释为True在 python 中。


推荐阅读