gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:33:44 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com