简体   繁体   English

如何使用 ChromeDriver 找到具有 Web 元素特定属性的所有后代

[英]How can I find all of the descendants with a specific attribute of an web element using ChromeDriver

While trying to figure out how to locate a specific group of web elements, I came across this question and I was wondering if I can do the same action just that it would give me only the descendants elements that contain a specific attribute.在试图弄清楚如何定位一组特定的 web 元素时,我遇到了这个问题,我想知道我是否可以执行相同的操作,只是它只会给我包含特定属性的后代元素。

For clarification, I know that I might be able to filter it but I'm looking for a way to do it without filtering.为了澄清起见,我知道我可能能够过滤它,但我正在寻找一种不过滤的方法。

Furthermore, I'm using java, and as web driver I use chrome driver (and I use Selenium for that, I don't know if it's obvious or not as that's the only web controlling tool that I learned so far...)此外,我使用的是 java,作为 web 驱动程序,我使用 chrome 驱动程序(为此我使用 Selenium,我不知道这是否明显,因为这是我迄今为止学到的唯一 web 控制工具......)

Github link Github 链接

Thanks for the answers ahead!感谢前面的答案!

To find elements with attribute that contains 'attributeValue':要查找具有包含“attributeValue”的属性的元素:

List<WebElement> childs = rootWebElement.findElements(By.xpath(".//*[contains(@attributeName,'attributeValue')]"));

To find elements with attribute that fully matches 'attributeValue':要查找具有完全匹配“attributeValue”的属性的元素:

List<WebElement> childs = rootWebElement.findElements(By.xpath(".//*[@attributeName='attributeValue']"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM