javascript - How to select the nth html element in a table that has special class? -


i using nightwatch.js test website. on website there table looks this:

<tr>     <td class="sorting_1">...</td>     <td class="sorting_2">...</td>     <td class="sorting_3">...</td>     <td class="sorting_3">...</td> </tr> 

now want check if table contains correct words. found out possible select element way:

'td[class="sorting_2"]' 

i can text command:

.gettext('td[class="sorting_2"]', function(result){     this.assert.equal(result.value, 'testbenutzer'); }) 

but have if want select 1 of 2 equally defined elements in list above. last 2 elements both have class sorting_3. how can nth element of table special class. tried this:

'td:nth-of-type(1)[class="sorting_3"]' 'td:nth-child(1)[class="sorting_3"]' 'td[class="sorting_3"]:nth-child(1)' 'td:nth-child(3)' 

nothing of worked. how can it?

the way can think of accessing multiple .sorting_3 elements, without knowledge of how nightwatch.js works, pass siblings ~ combinator selector.

i.e.: when want select first element out of .sorting_3 elements, this:

.gettext('td[class="sorting_3"]', function(result){     this.assert.equal(result.value, 'testbenutzer'); }) 

and second element:

.gettext('td[class="sorting_3"] ~ td[class="sorting_3"]', function(result){     this.assert.equal(result.value, 'testbenutzer'); }) 

and on ...

problem is, approach not scalable. need know ahead of time how many elements expecting in .sorting_3 selector.

hope helps.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -