Selenium ide并且需要在搜索记录后获取表计数

时间:2018-02-26 18:49:03

标签: selenium-ide

您好我正在使用selenium ide并且需要在搜索记录后获取表计数。该页面的示例是here

输入我要搜索的名称后,我想计算匹配的结果记录。我使用getXpathCount来计算记录,但它似乎没有增加计数器变量。

2 个答案:

答案 0 :(得分:0)

也许有更快的方法,但这个宏对我有用。我使用gotoif并执行循环,直到找不到更多的表行。然后n =循环次数=表行数。在Kantu Selenium IDE (Chrome)进行了测试。

{
  "CreationDate": "2018-2-26",
  "Commands": [
    {
      "Command": "open",
      "Target": "http://www.seleniumeasy.com/test/table-sort-search-demo.html",
      "Value": ""
    },
    {
      "Command": "sendKeys",
      "Target": "css=#example_filter > label > input",
      "Value": "london${KEY_ENTER}"
    },
    {
      "Command": "store",
      "Target": "1",
      "Value": "n"
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "verifyElementPresent",
      "Target": "css=#example > tbody > tr:nth-child(1) > td:nth-child(3)",
      "Value": ""
    },
    {
      "Command": "label",
      "Target": "countrows",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "${n}+1",
      "Value": "n"
    },
    {
      "Command": "echo",
      "Target": "n=${n}",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "css=#example > tbody > tr:nth-child(${n}) > td:nth-child(3)",
      "Value": ""
    },
    {
      "Command": "gotoIf",
      "Target": "${!LastCommandOK}",
      "Value": "countrows"
    },
    {
      "Command": "storeEval",
      "Target": "${n}-1",
      "Value": "n"
    },
    {
      "Command": "echo",
      "Target": "Number of table rows = ${n}",
      "Value": "green"
    }
  ]
}

结果:

enter image description here

答案 1 :(得分:0)

您可以在Selenium IDE中执行类似的操作 -

storeXpathCount    |   //table[@id='example']/tbody/tr/td[contains(.//text(),'Edinburgh')]     |    myVarCount

echo  |   ${myVarCount}