首页 > 解决方案 > 查找所有属性名称以“aria”开头的 HTML 元素

问题描述

在 Selenium 中使用 XPath 或在 Python 中使用 BeautifulSoup,如何通过知道这些属性以'咏叹调'

<a aria-label="Home" id="1" />
<button aria-hidden="True" id="2" />
<button aria-pressed="False" id="2" />

目前,我必须一个一个地输入所有属性,就像这样

driver.find_elements_by_xpath("//*[@aria-label]")
driver.find_elements_by_xpath("//*[@aria-pressed]")

我需要的是类似的东西(这里不正确),

driver.find_elements_by_xpath("//*@[starts-with('aria')]")

标签: seleniumselenium-webdriverxpathwai-aria

解决方案


推荐阅读