简体   繁体   中英

How to get find element injected on a page using puppeteer

There is a browser extension that modifies the page and inserts its own html code into it, I get the html code of the page being checked, but the html code injection from the extension does not get into it, although if you run the check in the browser, then there is an injection.

those. after rendering the page, the extension integrates a block inside the page:

<div><div class="notification"><div class="notification__close"></div> <div class="notification__logo"></div> <div class="notification__title">
  </div> <div class="notification__cta">
    Activate
  </div></div> <!----></div>

When trying to catch this block, puppeteer does not find it:

let browser = await puppeteer.launch ({
      headless: false,
      ignoreDefaultArgs: true,
      args: [
        `--load-extension = $ {path.join (dir, '/extension')},`
      ]
    });
let page = await browser.newPage ();

await page.goto ('https://site.url', {waitUntil: 'networkidle2'});
await page.waitForSelector ('.notification__cta');
await page.click ('.notification__cta');

I get a dump on timeout when trying to find an item:: Timeout - Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout. Timeout - Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout.Error:

If you look at the html that is stored in the page, then the notification block does not get there... Perhaps someone will have an idea how I can track html injections with a puppeteer and manipulate them?

I think you have a typo in your selector '. notification__cta' '. notification__cta' There should be no space between the dot and the classname. Does it work when you change it to '.notification__cta' ?

I think your extension is in the category of " Content Scripts ". At the moment they are not supported with puppeteer: see in the Docs, Working with Chrome Extensions :

NOTE It is not yet possible to test extension popups or content scripts.

solution in using query-selector-shadow-dom ( https://www.npmjs.com/package/query-selector-shadow-dom )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM