我正在使用此代码查找匹配的文本,我想查找重复的记录

WebElement body = driver.findElement(By.tagName("body"));
String bodyText = body.getText();

// count occurrences of the string
int count = 0;

// search for the String within the text
while (bodyText.contains("VIM LIQUID MARATHI")){

// when match is found, increment the count
count++;

// continue searching from where you left off
bodyText = bodyText.substring(bodyText.indexOf("VIM LIQUID MARATHI") + "VIM LIQUID MARATHI".length());


}

最佳答案

这将为您提供包含搜索文本的WebElement的每个文本:

String searchString = "VIM LIQUID MARATHI";
List<WebElement> elements = driver.findElements(By.xpath("//*[text() = '" + searchString + "']"));

for(WebElement we:elements){
   System.out.println(we.getText());
}

10-06 02:16