我是javascript的新宠,我试图在if条件旁边获取布尔值。下面是代码段
view.prototype.searchCustomer = function (customername) {
var customerFound = false;
var res = element.all(by.repeater('page in pages')).count().then(function (count) {
console.log("count of page count is " + count);
for (var i = 1; i <= count - 4; i++) {
element(by.xpath('//a[@class="ng-binding" and contains(text(),"rs")]'.replace("rs", i))).click();
element(By.xpath("//div[@class='cardHeader']/a[contains(text(),'" + customername + "')]")).isPresent().then(function (result) {
if (result) {
customerFound = true;
return result;
}
});
}
});
console.log("result is - "+customerFound);
};
在customerFound标志为true时,console.log始终返回false。任何人都可以帮我这个忙。我确实对Java和学习javascript有更好的了解。
谢谢
答案 0 :(得分:0)
尝试将var
更改为let
:
view.prototype.searchCustomer =函数(客户名){
let customerFound = false;
const res = element.all(by.repeater('page in pages')).count().then(function (count) {
console.log("count of page count is " + count);
for (let i = 1; i <= count - 4; i++) {
element(by.xpath('//a[@class="ng-binding" and contains(text(),"rs")]'.replace("rs", i))).click();
element(By.xpath("//div[@class='cardHeader']/a[contains(text(),'" + customername + "')]")).isPresent().then(function (result) {
if (result) {
customerFound = true;
return result;
}
});
}
});
console.log("result is - "+customerFound);
};