Sunday 24 February 2019

node.js puppeteer evaluate page and get id an index of element

Hi, i need help why this code it doesn't work i can get the currentID var currentID; const calendarArr = await page.evaluate(() => { const tds = Array.from(document.querySelectorAll('.table tbody td')) tds.forEach(function(el,index){ if (el.classList.contains('c') ){ console.log(el.id); console.log(index); currentID = index; } }); return tds.map(td => td.textContent ); }); console.log(calendarArr); // this works gives arr ['','1','2'.....] console.log(currentID); // this doesn't work undefined why the console.logs doesn't log? in tds.forEach and currentID isn't savedalso when i tried to use variable for selectors it doens't work never resulted and was stuck in waiting if i have likevar selector = '.table tbody td'; const calendarArr = await page.evaluate(() => { const tds = Array.from(document.querySelectorAll(selector)).... like i know how to get it work i split it into two separet page.evaluate() i just need to know why, what i'm missing. for any pointing out or directing to some resource would be appreciated

Submitted February 24, 2019 at 09:05AM by morflsd

No comments:

Post a Comment