我试图弄清楚如何获取下面的 view.html,并测试第一个元素/图 block 的列和行位置(.col 、 .row)。
<div class="container" gridster="gridsterOpts">
<ul>
<li>
<tile tilevalue="{{tile.tileId}}" gridster-item="tile" row="{{tile.row}}" col="{{tile.col}}" size-x="{{tile.sizeX}}" size-y="{{tile.sizeY}}" ng-repeat="tile in selectedTiles"/>
</li>
</ul>
</div>
有什么想法可以做到这一点吗?我不知道如何使用转发器调用,我想这就是解决方案的来源。
最佳答案
由于这是一个 Protractor 特定的问题 - 您可以使用内置 by.repeater()
locator并获取 first()
元素:
var firstTile = element.all(by.repeater("tile in selectedTiles")).first();
然后,要获取 row
和 col
属性值,请使用 getAttribute()
:
firstTile.getAttribute("row").then(function (row) {
console.log(row);
});
firstTile.getAttribute("col").then(function (col) {
console.log(col);
});
或者,如果您想断言值:
expect(firstTile.getAttribute("row")).toEqual("0");
expect(firstTile.getAttribute("col")).toEqual("0");
关于javascript - 如何编写一个 Protractor 测试来查找 'ng-repeat' 中的第一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37142457/