How to use consts when specifying attribute name in Jest with Puppeteer?

45 views Asked by At

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

0

There are 0 answers