Nightwatch.js循环通过表

时间:2015-06-25 11:35:45

标签: javascript html testing nightwatch.js system-testing

我正在使用Nightwatch.js编写一些系统测试。现在我想循环遍历表的所有元素并检查它们的值。我怎么能用Nightwatch.js做到这一点?该表的<tbody>元素包含多行<tr>。每行有几列<td>。我想得到每一行中每个第一个<td>元素的值。

3 个答案:

答案 0 :(得分:1)

Take a peek at this answer here. This talks a bit about how you can use the selenium WebElements to navigate through the tree then check the value of each.

It's a bit goofy; but essentially you'll want to write a custom command which you can do through the nightwatch.js custom commands that navigates through the tree checking the values you're looking to resolve.

答案 1 :(得分:0)

我无法添加评论,但在xpath选择器中使用xpath //table[@name="table_name"]/tbody/tr/td[1]来解决Petrogad提到的链接问题。

答案 2 :(得分:0)

类似地,我想迭代一个表。更具体地说,我想遍历TR,然后在每个TR的上下文中遍历TD。

我在这里找到了答案,如kunal_bohra发布的:NightWatch.js - get a list of child WebElements based on relative css locator