How to get a single element in Puppeteer

824 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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');