Element.getAttribute() 将 promisestatus 返回为待处理:量角器

Element.getAttribute() returning promisestatus as Pending : protractor

我的声明

var data = elmnt.getAttribute('row-id').then(function(value){
    rowid = value
    callback();
}); 
console.log('global var inside Rowid:'+ rowid);
console.log('global var inside data:'+ data);

我的输出

global var inside Rowid:null global var inside data:ManagedPromise::19682 {[[PromiseStatus]]: "pending"}

有人可以帮忙吗

啊,抱歉,没注意到 protractor 标签。

所以,如果我们有一个 promified getAttribute,那么这就是你使用 promises 的方式:

elmnt.getAttribute('row-id').then(function(rowId) {
    console.log(rowId);
}); 

您需要在承诺链中进行。 console.log(somePromise) 只会记录一个承诺,而不是一个值,并且 console.log(rowid) 在承诺被解决之前将产生 null/undefined.