[英]How to get first row value from table?
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>
<a href="#" ng-click="sortType = 'date'; sortReverse = !sortReverse">
Date-Time
</a>
</td>
<td><a>Amount</a></td>
<td><a>Transaction Type</a></td>
</tr>
</thead>
<tbody>
<!-- ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor0" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope">
<td class="ng-binding">Dec 8, 2016 4:44:43 PM</td>
<td class="ng-binding">210</td>
<td class="ng-binding">Credit</td>
</tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor1" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope">
<td class="ng-binding">Dec 8, 2016 4:45:08 PM</td>
<td class="ng-binding">100</td>
<td class="ng-binding">Debit</td>
</tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor2" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope">
<td class="ng-binding">Dec 13, 2016 10:54:03 AM</td>
<td class="ng-binding">1000</td>
<td class="ng-binding">Credit</td>
</tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor3" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope">
<td class="ng-binding">Dec 13, 2016 10:54:05 AM</td>
<td class="ng-binding">32</td>
<td class="ng-binding">Credit</td>
</tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor4" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope">
<td class="ng-binding">Dec 13, 2016 10:54:10 AM</td>
<td class="ng-binding">155</td>
<td class="ng-binding">Debit</td>
</tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor5" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope">
<td class="ng-binding">Dec 13, 2016 10:54:12 AM</td>
<td class="ng-binding">12</td>
<td class="ng-binding">Debit</td>
</tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end -->
</tbody>
</table>
這是HTML代碼,我想要第一行的日期時間量嗎?
使用以下代碼,您將能夠從第一行獲取日期:
element(by.repeater('tx in transactions')).element(by.tagName('td')).getAttribute('innerText').then(function(dateText){
console.log('Date for first row is::' + dateText);
});
如果您想對所有行執行相同的操作:
element.all(by.repeater('tx in transactions')).then(function(rows){
rows.forEach(function(row, index){
row.element(by.tagName('td')).getAttribute('innerText').then(function(dateText){
console.log('Date for ' + (index+1) + ' row is::' + dateText);
});
});
})
您可以參考以下文章,在此我編寫了用於檢索所有不同列值的代碼: https : //stackoverflow.com/a/41102952/7283782
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.