我一直在为我的 angular js 应用程序编写端到端测试,但我无法解决这个问题。我有一张包含数据的表格。我想提取第一行数据。
<table>
<tr>
<td><\td>
<td><\td>
<td><\td>
</tr>
</table>
我在 Protractor elementExplorer
中做了这个,它打印出了所有 3 列的值
element.all(by.repeater('item in items.list')).get(0).getText()
James
Byrne
1
如果我这样做,它会打印出第一列的值
element.all(by.repeater('item in items.list')).get(0).element(by.css('td')).getText()
WARNING - more than one element found for locator By.cssSelector("td") - the first result will be used
James
我的问题是,如何获取其他列的值?
最佳答案
var row = element.all(by.repeater('item in items.list')).first();
var cells = row.all(by.tagName('td'));
var cellTexts = cells.map(function (elm) {
return elm.getText();
});
然后,您可以断言它是一个列文本数组:
expect(cellTexts).toEqual(["The first text", "The second text", "The third text"]);
关于javascript - Protractor : Read Table contents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29501976/