Drhowell440
Drhowell440

Reputation: 33

Undefined variables on page.eval function using puppeteer

When I run this in my code it says that dottt is undefined, but why does it take in the pdfcitystatezipselector correctly. If I replace dottt with a string literal it works perfect.

const pdfcitystatezipselector = 'body > div:nth-child(1) > div:nth-child(6) > span';
  const dottt = "111111";

  await page.$eval(pdfdotselector, (element1, dotttt) => {


    element1.innerHTML = dottt;
  });

Upvotes: 1

Views: 735

Answers (1)

hardkoded
hardkoded

Reputation: 21617

You need to pass the dotttt argument to the $eval function:

const pdfcitystatezipselector = 'body > div:nth-child(1) > div:nth-child(6) > span';
const dottt = "111111";

await page.$eval(pdfdotselector, 
    (element1, dotttt) => {
       element1.innerHTML = dottt;
    },
    dotttt); // here

Upvotes: 4

Related Questions