Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Unable to modify element with puppeteer

I am trying to loop the students array and modify the html elements to print a card for each student.

However the code below fails at page.evaluate and gives the following error:

Evaluation failed: ReferenceError: student is not defined
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto(`file://${__dirname}/card/card.html`);

  console.log(students);

  for (const student of students) {
    console.log(student.name);
    await page.evaluate(() => {
      document.getElementById("name").innerHTML = student.name;
      document.getElementById("id").innerHTML = student.id;
      document.getElementById("text").innerHTML = student.text;
    });

    await page.screenshot({ path: `example-${student.id}.png` });
  }

  await browser.close();
})();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

page.evaluate() parameter is executed in the browser context, so you need to transfer any variables from Node.js context explicitly as additional arguments and parameters:

await page.evaluate((student) => {
  document.getElementById("name").innerHTML = student.name;
  document.getElementById("id").innerHTML = student.id;
  document.getElementById("text").innerHTML = student.text;
}, student};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!