我使用此代码来查找匹配的文本,我想查找重复的记录
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());
}
关于javascript - 如何使用 selenium webdriver 查找网页/表格中的重复文本/记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37564311/