1

I am trying to use consts when specifying attribute name, however i run into a problem where an error occurs ReferenceError: attr is not defined

  at evaluate (evaluate at CDPElementHandle.evaluate (node_modules/puppeteer-core/lib/cjs/puppeteer/api/ElementHandle.js:93:28), <anonymous>:2:47)
  at ExecutionContext._ExecutionContext_evaluate (node_modules/puppeteer-core/src/common/ExecutionContext.ts:334:34)
  at ExecutionContext.evaluate (node_modules/puppeteer-core/src/common/ExecutionContext.ts:189:12)
  at CDPJSHandle.evaluate (node_modules/puppeteer-core/src/common/JSHandle.ts:83:12)
    const attr='data-jest';
    .....
    const element = await page.waitForSelector(`[${attr}]`);

    const testUri = await element.evaluate((el) => {
        console.log(el);
        return el.getAttribute(attr );
    });

changing attr to literal string works

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
  • Does this answer your question? [How can I pass variable into an evaluate function?](https://stackoverflow.com/questions/46088351/how-can-i-pass-variable-into-an-evaluate-function) – Ricky Mo May 22 '23 at 06:20

0 Answers0