Nightwatch.js loop through table

6k Views Asked by At

I am using Nightwatch.js to write some System Tests. Now I want to loop through all elements of a table and check their values. How can I do this with Nightwatch.js? The table has a <tbody> element containing several rows <tr>. Every row has several columns <td>. I want to get the values of every first <td> element in every row.

3

There are 3 best solutions below

0
On

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.

0
On

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.

I found my answer here, as posted by kunal_bohra: NightWatch.js - get a list of child WebElements based on relative css locator

0
On

I cannot add comment but use xpath //table[@name="table_name"]/tbody/tr/td[1] in xpath selector to the linked question that Petrogad mentioned.