How to get a row and its column from a table using Protractor
<div class="k-grid-content">
<table>
<tbody>
<tr>
<td>row1Col1</td>
<td>row1Col2</td>
<td>row1Col3</td>
</tr>
<tr>
<td>row2Col1</td>
<td>row3Col2</td>
<td>row4Col3</td>
</tr>
<tr>
<td>row3Col1</td>
<td>row3Col2</td>
<td>row3Col3</td>
</tr>
</tbody>
</table>
</div>
var grid = element.all(by.css('.k-grid-content tr')); //this will return row1,row2,row3
but I cannot use the code below to get each row and its column.
grid.each.each(function(row){
var rowElems = row.findElements(by.tagName('td'));
expect(rowElems.get(0).getText()).toMatch('/Col1/');
});
The following error message is displayed. Message: TypeError: Object [object Object] does not have a findElements method
+4
1 answer
Your setup gridis fine, but for the sake of a shortcut:
var grid = $$('.k-grid-content tr');
Regarding your question, avoid findElementsand use binding, elementor in this case the allProtractor Function. But I'm using the $$shortcut again :
grid.each(function(row) {
var rowElems = row.$$('td');
expect(rowElems.count()).toBe(3);
expect(rowElems.get(0).getText()).toMatch('/Col1$/');
});
+10