我有以下代码:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
将它转换为使用Java 8 Stream的正确方法是什么?
当我试图使用时map(),我得到一个错误,因为getAttribute不是Function.
int a = (int) blogImagesList.stream()
.map(WebElement::getAttribute("style"))
.filter(s -> s.contains(imageSrc))
.count();
Run Code Online (Sandbox Code Playgroud) 假设我有以下代码:
public int getNumOfPostInstancesByTitle(String postMainTitle) {
int numOfIns = 0;
List<WebElement> blogTitlesList = driver.findElements(blogTitleLocator);
for (WebElement thisBlogTitle : blogTitlesList) {
String currentTitle = thisBlogTitle.getText();
if (currentTitle.equalsIgnoreCase(postMainTitle)) {
numOfIns++;
}
}
return numOfIns;
}
Run Code Online (Sandbox Code Playgroud)
用谓词lambda转换它的正确方法是什么?