How to handle an AppStore modal window with Puppeteer?

Viewed 273

I'm trying to scrape some data from Version History modal window on AppStore.

For some reason Puppeteer ignores the request. That's how the screen I want to scrape looks:

screenshot

What I've tried. I have a guess that maybe this modal window is not recognized as a popup.

    await page.waitForSelector("div[data-test-we-modal=page-overlay]")
    const link = await page.$('div[data-test-we-modal=page-overlay]')
    const modalPromise = new Promise(x => page.once('popup', x));
    await link.click()
    const modal = await modalPromise; 
    await modal.waitForSelector('button[class=we-modal__close]')
    await modal.click('button[class=we-modal__close]')
1 Answers

Some adjustments:

  1. It seems popup is a new tab or window, while in your case the dialog is just DOM element with blocking style, so you just need to wait for a selector.
  2. The click on the element to open the dialog needs some scripts to be loaded and executed, so additional time or goto() load option can help.
'use strict';

const puppeteer = require('puppeteer');

(async function main() {
  try {
    const browser = await puppeteer.launch( { headless: false, defaultViewport: null });
    const [page] = await browser.pages();

    await page.goto(
      'https://apps.apple.com/us/app/instagram/id389801252',
      { waitUntil: 'networkidle0' },
    );

    await page.waitForSelector('div[data-test-we-modal=page-overlay] button');
    const link = await page.$('div[data-test-we-modal=page-overlay]');
    await link.click();

    await page.waitForSelector('button[class=we-modal__close]');
    await page.waitFor(3000);
    await page.click('button[class=we-modal__close]');

    await browser.close();
  } catch (err) {
    console.error(err);
  }
})();
Related