I have the following code:
public boolean isImageSrcExists(String imageSrc) {
int resultsNum = 0;
List<WebElement> blogImagesList = driver.findElements(blogImageLocator);
for (WebElement thisImage : blogImagesList) {
if (thisImage.getAttribute("style").contains(imageSrc)) {
resultsNum++;
}
}
if (resultsNum == 2) {
return true;
} else {
return false;
}
}
What is the proper way of converting it to use Java 8 Stream
s?
When I'm trying to use map()
, I get an error since getAttribute
isn't a Function
.
int a = (int) blogImagesList.stream()
.map(WebElement::getAttribute("style"))
.filter(s -> s.contains(imageSrc))
.count();