我的网页上有一个包含9行和6列的表格.我想搜索文本"MakeGoodDisabled-Programwise_09_44_38_461(n)"并获取单元格的xpath.我使用了以下但它失败了,因为它无法在页面中找到文本.你能帮忙吗?我正在使用Selenium Webdriver Junit对此进行编码.
List < WebElement > links = driver.findElements(By.tagName("td"));
Iterator < WebElement > itr = links.iterator();
while (itr.hasNext()) {
String test = itr.next().getText();
if (test.equals("MakeGoodDisabled-Programwise_09_44_38_461(n)")) {
String xpath = driver.findElement(By.name(test)).getAttribute("xpath");
System.out.println(xpath);
}
}
Run Code Online (Sandbox Code Playgroud) 嗨,我想计算一下文本Ex:"VIM LIQUID MARATHI"出现在页面上使用selenium webdriver(java)多少次.请帮忙.
我使用以下内容检查主要类中使用以下内容是否在页面中显示文本
assertEquals(true,isTextPresent("VIM LIQUID MARATHI"));
和一个返回布尔值的函数
protected boolean isTextPresent(String text){
try{
boolean b = driver.getPageSource().contains(text);
System.out.println(b);
return b;
}
catch(Exception e){
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
...但不知道如何计算出现次数......