简体   繁体   English

Nightwatch.js在表中循环

[英]Nightwatch.js loop through table

I am using Nightwatch.js to write some System Tests. 我正在使用Nightwatch.js编写一些系统测试。 Now I want to loop through all elements of a table and check their values. 现在,我想遍历表的所有元素并检查它们的值。 How can I do this with Nightwatch.js? 如何使用Nightwatch.js? The table has a <tbody> element containing several rows <tr> . 该表具有一个<tbody>元素,其中包含几行<tr> Every row has several columns <td> . 每行都有几列<td> I want to get the values of every first <td> element in every row. 我想获取每一行中每个第一个<td>元素的值。

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. 这里讨论了如何使用硒WebElement在树中导航,然后检查每个元素的值。

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. 但实际上,您需要编写一个自定义命令,您可以通过nightwatch.js 自定义命令来完成该任务 ,该命令可在树中导航并检查您要解析的值。

我无法添加注释,但可以在xpath选择器中将xpath //table[@name="table_name"]/tbody/tr/td[1]用于Petrogad提到的链接问题。

Similarly, I wanted to iterate a table. 同样,我想迭代一个表。 More specifically, I wanted to iterate over the TRs, and then in the context of each TR, iterate over the TDs. 更具体地说,我想遍历TR,然后在每个TR的上下文中遍历TD。

I found my answer here, as posted by kunal_bohra: NightWatch.js - get a list of child WebElements based on relative css locator 我在这里找到了答案,如kunal_bohra发布的: NightWatch.js-根据相对的CSS定位器获取子级WebElement的列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM