您好,下面是我的html表。我正在尝试使用量角器比较下表中的所有元素值。
<table>
<thead class="ui-table-thead">
<tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
<th _ngcontent-c1="" class="ng-tns-c1-0" rowspan="2" style="text-align: center">User</th>
<th _ngcontent-c1="" class="ng-tns-c1-0" colspan="5" style="text-align: center">Support</th>
</tr>
<tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
<th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User1</th>
<th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User2</th>
<th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User3</th>
<th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User4</th>
<th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User4</th>
</tr>
</thead>
<tbody class="ui-table-tbody">
<tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
<td _ngcontent-c1="" class="ng-tns-c1-0">value1</td>
<td _ngcontent-c1="" class="ng-tns-c1-0">value2</td>
<td _ngcontent-c1="" class="ng-tns-c1-0">value3</td>
</tr>
<tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
<td _ngcontent-c1="" class="ng-tns-c1-0">value11</td>
<td _ngcontent-c1="" class="ng-tns-c1-0">value12</td>
<td _ngcontent-c1="" class="ng-tns-c1-0">value13</td>
</tr>
<tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
<td _ngcontent-c1="" class="ng-tns-c1-0">value21</td>
<td _ngcontent-c1="" class="ng-tns-c1-0">value22</td>
<td _ngcontent-c1="" class="ng-tns-c1-0">value23</td>
</tr>
</tbody>
</table>
无法获得正确的解决方案。我们将为您提供任何帮助。谢谢
答案 0 :(得分:0)
尝试一下:
function AddBetternameforfuntionhere(){
var headerRows = element.all(by.css(".ui-table-thead")).first().all(by.tagName('tr'));
var headerIndex = headerRows.all(by.tagName('th'));
var counter = 0;
headerIndex.getText().then(function(conforms){
conforms.forEach(function(value){
//perform the validation here
})
})
}
forEach将迭代直到.getText()中的数组结尾
对于主体,代码是相似的,例如,如果您想验证特定的列,则可以使用它来获取值:
var expectedCells = element.all(by.css('#'+/*TableId*/+' tr td:nth-of-type('+columnNumber+')'));
expectedCells.each((eachCell) => {
eachCell.getText().then((cellText) => {
expect(cellText).toBe(arrayOfvalues);
});
});