简体   繁体   English

仅使用一个列表查找与 xpath 匹配的所有 WebElement 的文本

[英]Finding text of all WebElements that match a xpath using only one List

There is any way to find the text of WebElements that match a xpath by only using one List?有什么方法可以通过仅使用一个列表来找到与 xpath 匹配的 WebElements 文本? Normaly what I do is:通常我所做的是:

List<WebElement> listOfWe = driver.findElements(By.xpath("..."));
List<String> listOfStrings = new Array<>();
for (WebElement we:listOfWe ){
    listOfStrings.add(we.getText());
}

In that case I am using two Lists but I want to use only one.在这种情况下,我使用了两个列表,但我只想使用一个。 Does anybody know how can I do it?有人知道我该怎么做吗?

this should work for you:这应该适合你:

final List<String> texts = webDriver.findElements(By.xpath("...")).stream()
                                            .map(WebElement::getText)
                                            .collect(toList());

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

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