Skip to main content

To wait for multiple selectors to be loaded using Puppeteer and Node.js, you can make use of the `waitForSelector` function in conjunction with `Promise.all`. Here's an example of how you can accomplish this:

const puppeteer = require('puppeteer');

async function waitForSelectors() {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('');

  const selectors = [
    // Add more selectors as needed

  // Create an array of promises for each selector
  const promises = => page.waitForSelector(selector));

  // Wait for all promises to resolve
  await Promise.all(promises);

  console.log('All selectors loaded!');

  // Continue with your code after all selectors are loaded

  await browser.close();


In the above example, we create an array of selectors that we want to wait for using `waitForSelector`. Then, we use `map` to create an array of promises, with each promise waiting for a specific selector to be loaded.

By passing the array of promises to `Promise.all`, we wait for all the promises to resolve, which means that all the selectors have been successfully loaded. After that, you can continue with your code.

Remember to replace the selectors in the `selectors` array with the actual CSS selectors you want to wait for. You can add as many selectors as you need.