2016-12-14 56 views
0
<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代码,我想要第一行的日期时间量?如何从表中获取第一行值?

+0

请花几分钟在此处了解代码格式化工具,然后使用预览窗格检查问题是否可读。谢谢。 – halfer

+0

这里是示例代码 –

+0

它(“测试字段”,函数(){browser.get('http://www.way2automation.com'); element.all(by.repeater('tx in transactions' ))。then(function(rows){columns(0).getAttribute('))。然后(函数(行){row.forEach(函数(行){row.all(by.tagName('td'))然后(function(dateText){console.log('Date:'+ dateText);}); columns [1] .getAttribute('innerText')。then(function(amountText){console.log 'amount:'+ amountText);}); columns [2] .getAttribute('innerText')。then(function(transactionType){console.log('Transaction Type:'+ transactionType);});}); }); –

回答

0

使用下面的代码,你将能够从第一行获取日期:

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); 
     }); 
    }); 
}) 

你可以参考下面的帖子,在t他编写了用于检索所有不同列值的代码: https://stackoverflow.com/a/41102952/7283782

+0

谢谢哟它的工作原理...但如何检查console.log输出?因为浏览器如此快速关闭 –

+0

明白了..谢谢你 –

+0

太好了,那么请将此标记为已接受的答案。会帮我得分:) – rk30

0

这个问题非常含糊,请包括您尝试过的一些代码示例。

但是,您可以将“id”应用于包含所需数据的元素。然后,您可以使用一些简单的JavaScript来获取该元素的值。

var el = document.getElementById('');

el.value;

相关问题