Why var ProductArr=[]
is not accessible inside the while
loop, and how can I access it?
What is the solution if I want to continue the array and reinitialize every time in a loop?
Also is there any way I can access the `var ProductArr=[]' variable inside while?
var productArr = [];
while(await page.$(".paging-next.ng-star-inserted .iconAct-Chevron_Right")){
var grabProducts = await page.evaluate(() => {
let products = document.querySelectorAll(".ng-tns-c226-3.ng-trigger.ng-trigger-staggerFadeInOut.product-grid .shelfProductTile-description a");
//var productArr = [];
products.forEach(tag => {
productArr.push(i+' '+tag.innerText)
i++;
});
return productArr;
});
await page.click(".paging-next.ng-star-inserted .iconAct-Chevron_Right");
await page.waitForTimeout(5000);
}