Search code examples
javascriptnode.jspuppeteerwebautomation

How to get a single element in Puppeteer


Is it possible to just get a single element with puppeteer and not an array? I keep seeing:

const elements = await page.$$('.some-class');

Is it possible just to get one element without an array?


Solution

  • page.$ maps to document.querySelector and page.$$ maps to document.querySelectorAll. If you want to get only one element you can use page.$:

    const element = await page.$('.some-class');