从量角器中的row元素获取索引

时间:2017-07-13 13:33:44

标签: angularjs testing protractor

我使用Protractor在表中搜索一行。我想在其中一列中使用特定ID的特定行。使用过滤器列表,我能够读取该id,但现在我想知道哪个行索引对应该id。

element.all(by.repeater('item in list)')).count().then(function (count) {
var list = element.all(By.binding('item.ID'));

var ID = list.filter(function (elem) {
    return elem.getText().then(function (text) {
        return text === myID;
    });
}
expect(ID.getText()).toBe(myID)); 

问题是我想从另一列读取值但是来自同一个元素,所以我需要索引。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您可以使用.each来携带元素的元素索引。

  var theIndex;
  element.all(by.repeater('item in list')).each(function (theElement, index) {
     if( **Test this is the correct item** ){
       theIndex = index;
     }
  });

  browser.driver.sleep(0).then(function () {
    // Use theIndex
  });