【发布时间】:2014-04-23 17:02:03
【问题描述】:
我是 AngularJS/量角器的新手,因此非常感谢任何有关这方面的指导。 由于 Angular JS 通过 ng- 指令实例化 html 元素,因此没有允许我定位特定元素的“id”等。 (显然我想这样做来验证内容,点击它们等) 我的 Angular js sn-p 看起来像:
<div ng-repeat="item in myList">
<span ng-if="item.category == 'lights'">
<img src="../../../{{item.icon}}"/>
 <span id="foo">{{item.name}}</span> 
</span>
</div>
当我用这个遍历列表时,我正在尝试定位元素 {{item.name}}:
element.all(by.repeater('item in myList')).then(function(rows) {
noOfItems = rows.length;
for (i = 0; i < noOfItems; i++) {
row = element.all(by.repeater('item in myList')).get(i);
row.isElementPresent(By.id('foo')).then(function (isP) {
if (isP) {
console.log("foo exists?" + isP);
row.findElement(By.id('foo')).then(function (el) {
el.getText(txt).then(function (txt) {
console.log("Item name " + txt);
});
});
}
});
}
});
从检查来看,“行”元素似乎是硒对象,所以我调用了“isElementPresent(...)”,这很好用。它检测正确数量的“foo”元素。但是,当 row.findElement(...) 运行时,测试规范会提前终止。 (没有错误,就结束了)
我知道文档中会有多个“foo”元素,但是我希望由于它们是在子 html 元素中查询的,(行)这可能会起作用。
有什么建议/解决方法吗?
【问题讨论】:
-
奇怪,row.findElement(...) 应该会抛出错误,因为它是一个数组,不应该有函数 findElement。 row[0].findElement 应该可以工作。 “foo 存在吗?”出现在控制台日志中?
标签: javascript angularjs selenium protractor