javascript - 关于量角器中 then 函数的参数。在下面的代码中,什么将传递给“值”?
问题描述
如果 bar 等于 jsonObj.alias 它应该返回 true 或 false 并且这应该是 next then 函数正确的参数。但这不是在这里发生的。请清除这一点。最后一个 then 函数的参数是什么以及如何?
element
.all(by.repeater('portGroup in displayedCollection'))
.filter(function(eachRow) {
return eachRow.element(by.css('td:nth-child(2)')).getText().then(function(bar){
return bar === jsonObj.alias;
});
})
.then(function(values){
values[0].element(by.css('span[class="ng-binding"]')).click();
});
解决方案
将你的代码分成两部分可以让你理解你的问题。
var satisfiedRows = element
.all(by.repeater('portGroup in displayedCollection'))
.filter(function(eachRow) {
// the filter function is to find out from all rows
// which's 3rd cell text equal to `jsonObj.alias`
return eachRow.element(by.css('td:nth-child(2)')).getText().then(function(bar){
return bar === jsonObj.alias;
});
}); // we can split your code at here
// satisfiedRows is a promise which eventual value are satisfied rows
// you call `then()` on this promise, the argument `function()` will be
// passed-in the promise's eventual value. In your case,
// they are rows which's 3rd cell text equal to `jsonObj.alias`
satisfiedRows.then(function(rowsAfterFilter){
rowsAfterFilter[0].element(by.css('span[class="ng-binding"]')).click();
});
推荐阅读
- css - 样式表更改后 Chrome 66+ SVG 不更新颜色
- php - PHP嵌套包含在批处理php过程中
- sharepoint - 如何在 SPFx 中使用本地化资源?
- mysql - 出现错误无法执行语句:由于 BINLOG_FORMAT = STATEMENT 无法写入二进制日志
- c# - Task.Delay vs Thread.Sleep 用于暂停 System.Timers.Timer 的工作
- watson-conversation - 如何在沃森助手(对话)上不混淆地在对话之间跳转?
- javascript - 使 Meteor 子文档具有响应性
- postgresql - 如何在postgres中返回x标准差的中位数和值
- firebase - Firebase:验证电子邮件在几次后停止发送
- python - 如何创建动态棉花糖字段(也就是以编程方式更改用于序列化的字段)?