2017-05-25 100 views
0
<table> 
    <thead> 
     <th>name</th> 
     <th>place</th> 
     <th>area</th> 
    </thead> 
    <tbody> 
     <tr><td>name</td><td>jjhds</td><td>dfdsf</td></tr> 
     <tr><td>name</td><td>jjhds</td><td>dfdsf</td></tr> 
     <tr><td>name</td><td>jjhds</td><td>dfdsf</td></tr> 
     <tr><td>name</td><td>jjhds</td><td>dfdsf</td></tr> 
     <tr><td>name</td><td>jjhds</td><td>dfdsf</td></tr> 
    </tbody> 
</table> 

我有上表。我需要从tdtbody导航,并通过量角器得到其标题thead **** th。请任何人都可以帮忙?量角器中特定索引表中的th元素

+0

你究竟想在这里做什么?可能会放一些你已经尝试过的逻辑。这样,用选择器或者更好地理解它会更容易。 – BKS

回答

0

一种选择是获得一个列的索引所需的标题一排,样品:

var table = $('table'); // TODO: too general of a locator, improve 
var headers = table.$$('th'); 
table.$$('tr').each(function (row) { 
    row.$$('td').each(function (cell, index) { 
     cell.getText().then(function (cellText) { 
      headers.get(index).getText().then(function (headerText) { 
       console.log("Header: " + headerText + ", Cell Value: " + cellText); 
      }); 
     }); 
    }); 
}); 

使用.each()这里只是为了演示的目的。

+0

非常感谢,:) ..它正在工作:) – reddy