check text is present in table (selenium IDE)

时间:2016-04-25 09:00:18

标签: selenium xpath selenium-ide

I am trying to check that the text "AUTOTEST" is present somewhere in my HTML table "tableTest". In selenium IDE, i put this code :

<tr>
    <td>verifyTextPresent</td>
    <td>//table[@id='tableTest']</td>
    <td>AUTOTEST</td>
</tr>

Here is the code of the HTML table :

<table id="myTable">
  <tr>
    <td><a href="#">AUTOTEST</a></td>
    <td>TEST</td>
  </tr>
  <tr>
    <td><a href="#">UOI</a></td>
    <td>TEST</td>
  </tr>
</table>

But the assertion always return false whereas text is well present in the table. Which command can i use to check that text is present in my table ?

2 个答案:

答案 0 :(得分:0)

我认为这样做的原因是您尝试使用整个表作为定位器来验证一位文本,而不是包含您正在寻找的文本的特定部分,作为结果它不匹配,因为您在表格中有其他内容,并且您的验证步骤正在寻找完全匹配。您需要在selenium脚本中放置AUTOTEST周围的通配符,这样它只会确保它存在于表中的某个位置。

针对您为表格提供的HTML代码进行脚本和日志测试。

<tr>
    <td>verifyText</td>
    <td>css=table</td>
    <td>*AUTOTEST*</td>
</tr>

[info] Playing test case Untitled
[info] Executing: |verifyText | css=table | *AUTOTEST* |
[info] Test case passed 

答案 1 :(得分:0)

VerifyTextPresent已被删除,VerifyText将执行您想要的操作:

<tr>
<td>verifyText</td>
<td>//table[@id='myTable']</td>
<td>*AUTOTEST*</td>
</tr>

另外需要注意的是文本是FULL文本,因此在这种情况下,您需要使用glob并使用*作为通配符。

注意:顺便说一下你也可以像这样指定id(而不是完整的xpath):

<tr>
    <td>verifyText</td>
    <td>myTable</td>
    <td>*AUTOTEST*</td>
</tr>
相关问题