gpt4 book ai didi

javascript - Protractor - TypeError : undefined is not a function

转载 作者:行者123 更新时间:2023-11-30 09:59:09 26 4
gpt4 key购买 nike

这个问题有两个目的,试图解决这个特定的错误,并试图理解 Protractor 的最佳实践。所以,我有以下失败的测试代码:

var newRow = element.all(by.repeater("employee in ec.employees")).last();

newRow.then(function(row) {
row.findElements(by.tagName("td")).then(function(cells) {
expect(cells.get(0).getText()).toBe("9988776655000");
expect(cells.get(1).getText()).toBe("Test name");
expect(cells.get(2).getText()).toBe("Test surname");
});
});

原因:

TypeError: Undefined is not a function

它指向第二行代码 newRow.then(...)

我的相关 HTML:

<tr ng-repeat="employee in ec.employees">
<td>{{employee.jmbg}}</td>
<td>{{employee.name}}</td>
<td>{{employee.surname}}</td>
</tr>

现在,我已经在 SO 上看到许多关于此错误的帖子,但所有帖子都是具体的,而且据我所知,没有一个与我的案例相似。所以,除了为什么我的代码不起作用的问题,我想问的是使用 ElementFinder.findElement/s 函数更好,还是有其他选择?

最佳答案

element.all(...).last() 返回一个 ElementFinder,因此您不能像 promise 一样使用它。更改您的代码以直接在 newRow 变量上查找元素。方法如下 -

var newRow = element.all(by.repeater("employee in ec.employees")).last();

newRow.findElements(by.tagName("td")).then(function(cells) {
expect(cells.get(0).getText()).toBe("9988776655000");
expect(cells.get(1).getText()).toBe("Test name");
expect(cells.get(2).getText()).toBe("Test surname");
});

希望这对您有所帮助。

关于javascript - Protractor - TypeError : undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32579812/

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