0

I have this code in a puppeteer script. I need to access to the informations that are part of a table. I've tried with the page.$$eval() function but nothing is logged into console. What's wrong with the code?

(async() => {
  const browser = await puppeteer.launch({
    headless: false
  });

  const page = await browser.newPage();

  page.goto(process.env.GATEWAY_ADDRESS, { waitUntil: ['load', 'networkidle2']});

  const pwdField = await page.waitForSelector('#srp_password');
  await pwdField.type(process.env.GATEWAY_PASSWORD);

  const submitBtn = await page.waitForSelector('#sign-me-in');
  await submitBtn.click();

  page.waitForNavigation().then( (response) => {
    page.goto(process.env.GATEWAY_PAGE, { waitUntil: ['load', 'networkidle2']}).then( (response) => {
      page.$$eval('#calllog > tbody > tr', (rows) => {
        console.log(rows);
        // let rowsData = [];
        // rows.forEach( (row) => {
        //   console.log(row);
        // });
      });
    });
  });

})();
newbiedev
  • 2,607
  • 3
  • 17
  • 65
  • `console.log(rows);` — this logs into the browser console, not into the system shell. Do you check the browser console? – vsemozhebuty Mar 06 '21 at 23:25
  • @vsemozhebuty I don't checked the chromium console but usually all the evdents are logged in vs console or terminal. – newbiedev Mar 07 '21 at 07:25
  • 2
    The callback argument of `page.$$eval()` is executed in the browser document context, so it uses the browser console. If you need the data in vs console or terminal, you need to return the serializable data from this callback and then call `console.log()` in Node.js context, not in browser document context – vsemozhebuty Mar 07 '21 at 10:26
  • Yeah, I was realizing this after checking the chromium console. I'm selecting the `td` of the table I'm targeting using `page.$$eval(''#calllog tbody tr td'')` after this I will push the values inside the `rowsData` array. I will return the array and then use the data in console. – newbiedev Mar 07 '21 at 10:30
  • Does this answer your question? [Puppeteer log inside page.evaluate](https://stackoverflow.com/questions/46198527/puppeteer-log-inside-page-evaluate) – ggorlen Mar 09 '21 at 17:23

0 Answers0