javascript - 如何使用 selenium webdriver 查找网页/表格中的重复文本/记录?

标签 javascript java selenium

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

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/

相关文章:

java - 如何自动化 Gmail 登录以在 Java 8 中使用 HttpsURLConnection 和 Jsoup

python - 努力使用 Selenium 刮 table

javascript - 使用字符串变量的动态 if 语句

javascript - 使用 es6 map 将数组转换为对象

java - 如何解决 "org.hibernate.MappingException: Unknown entity"错误?

java - MIDI 序列,注释命令并不总是跟随注释关闭

java - 在 Selenium 中,使用显式等待时是否需要禁用隐式等待?

python - 如何打包和分发具有需要安装驱动程序的依赖项的 Python 项目?

javascript - 将参数传递给调用的事件处理程序,即 element.onchange(); javascript

javascript - FB.Connect.showPermissionDialog 后重定向的问题