无法获取长度 [英] Unable to get the length
本文介绍了无法获取长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 JavaScript 概念的新手.为什么我得到相同变量 length 的不同输出?虽然它在体内显示预期的结果?
I am novice to javascript concepts. Why i am getting the different output for the same variable length? While it is showing the expected result inside the body ?
var length;
element.all(by.className("className")).getText().then(function(items){
length = items.length;
console.log("1st output = "+length);//1
console.log("2nd output = "+items.length);//1
});
console.log("3rd output = "+length);//undefined
输出:-第一个输出 = 1
Output:- 1st output = 1
第二个输出 = 1
第三个输出 = 未定义
3rd output = undefined
推荐答案
因为您的 all()
是异步调用,所以 console.log
将在您完成 then
链接并赋值给 length
Because your all()
is async call so console.log
will run before you finish then
chain and assign value to length
这篇关于无法获取长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文