gpt4 book ai didi

javascript - Protractor : Read Table contents

转载 作者:数据小太阳 更新时间:2023-10-29 05:00:04 24 4
gpt4 key购买 nike

我一直在为我的 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

我的问题是,如何获取其他列的值?

最佳答案

使用all()连同map() :

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com