Friends helped me with a solution that validates if there are [active/inactive] records in the list. When I list the records using pp capybara also returns blank lines. How do I disregard empty records?
def validate_active_inactive_records
expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/)
# ***listing records***
page.all('.tvGrid tr > td:nth-child(5)').each do |td|
puts td.text
end
end
<table width="100%" >
<tbody>
<tr>
<th colspan="1" >Id</th>
<th colspan="1" >Code</th>
<th colspan="1" >Description</th>
<th colspan="1" >Operational Center</th>
<th colspan="1" >Status</th>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
CodePudding user response:
Are you asking how to remove the rows with the class tvRowEmpty
from your search results? If so, you can use the :not
operator in your finder:
def validate_active_inactive_records
expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/)
# ***listing records***
page.all('.tvGrid tr:not(.tvRowEmpty) > td:nth-child(5)').each do |td|
puts td.text
end
end
If you want to exclude any td
that just contains
you could use the following finder with a regex that filters tags containing only whitespace characters:
page.all('.tvGrid tr > td:nth-child(5)', text: /[\s]^*/).each