小编Nan*_*shi的帖子

按文本查找元素并获取xpath - selenium webdriver junit

我的网页上有一个包含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)

junit selenium selenium-webdriver

10
推荐指数
4
解决办法
8万
查看次数

文本出现在网页中的次数 - Selenium Webdriver

嗨,我想计算一下文本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)

...但不知道如何计算出现次数......

java selenium selenium-webdriver

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

selenium ×2

selenium-webdriver ×2

java ×1

junit ×1