2016-12-01 59 views
0

使用行號我已經現有的方法類似下面,如何獲得TD元素沒有量角器

getSpecificCell: function(tableObject, rowNumber, columnCss) { 
    var ele = element(by.repeater(tableObject).row(rowNumber)).element(by.css('[' + columnCss + ']')); 
    return ele; 
} 

這有可能使用該行的文本,而不是ROWNUMBER這樣做?

表格下面的HTML我需要的列值,而無需使用行號

HTML樣本:

<table class="table"> 
    <thead> 
    <tr> 
     <th class="checkbox-column"></th> 
     <th class="main-column main-column--checkbox">Name</th> 
    </tr> 
    </thead> 
    <tbody ng-repeat="(a, b) in tests" class="ng-scope" style=""> 
    <tr class="panel__sub-header"> 
     <td> 
     <input name="item-checkbox" ng-click="toggleSelectAll(a)" type="checkbox"> 
     </td> 
     <td colspan="4"> 
     <h4 class="ng-binding">ROW2</h4> 
     </td> 
    </tr> 
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style=""> 
     <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td> 
     <td class="main-column"> 
     <a ng-href="#" class="ng-binding" href="#">test.name</a> 
     </td> 
    </tr> 
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style=""> 
     <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td> 
     <td class="main-column"> 
     <a ng-href="#" class="ng-binding" href="#">test.data</a> 
     </td> 
    </tr> 
    </tbody> 
    <tbody ng-repeat="(a, b) in tests" class="ng-scope" style=""> 
    <tr class="panel__sub-header"> 
     <td> 
     <input name="item-checkbox" ng-click="toggleSelectAll(a)" type="checkbox"> 
     </td> 
     <td colspan="4"> 
     <h4 class="ng-binding">ROW1</h4> 
     </td> 
    </tr> 
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style=""> 
     <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td> 
     <td class="main-column"> 
     <a ng-href="#" class="ng-binding" href="#">test.name</a> 
     </td> 
    </tr> 
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style=""> 
     <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td> 
     <td class="main-column"> 
      <a ng-href="#" class="ng-binding" href="#">test.data</a> 
     </td> 
    </tr> 
    </tbody> 
</table> 
+0

你可以做到這一點,但爲表格元素提供相關的HTML代碼,其中有一些行。 –

+0

那麼基於哪個行值需要過濾? –

+0

是的。 (by.repeater(tableObject).row(rowNumber))。element(by.css('['+ columnCss +']')); 從這而不是行(rowNumber)我需要使用行文本(ROW2) – Prabhu

回答

0

您可以使用filter()方法WebElement的濾鏡陣列。看看下面的例子,

getSpecificCell: function(tableObject, expectedRowValue, columnCss) { 
    var ele =element.all(by.repeater(tableObject).filter(function(rowElement){ 
     return rowElement.element(by.css("td h4")).getText().then(function(rowValue){ 
     return rowValue == expectedRowValue; 
     }) 
    }).first().element(by.‌​css('[' + columnCss + ']')); 

return ele; 
} 
+0

我試過這與element.all,但面臨以下錯誤 '索引超出限制。嘗試訪問索引爲0的元素,但只有0個元素匹配定位符by.repeater' – Prabhu

+0

您需要使用'element.all(by.repeater())'。更新了我的答案。 –

+0

是的,用'element.all(by.repeater())'嘗試過後才面對上面的錯誤 – Prabhu