     [Answers](https://scrapfly.io/blog)   /  [data-parsing](https://scrapfly.io/blog/tag/data-parsing)   /  [How to find elements by CSS selector in Puppeteer?](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-in-puppeteer)   # How to find elements by CSS selector in Puppeteer?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Oct 28, 2022 1 min read [\#data-parsing](https://scrapfly.io/blog/tag/data-parsing) [\#headless-browser](https://scrapfly.io/blog/tag/headless-browser) [\#puppeteer](https://scrapfly.io/blog/tag/puppeteer) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-css-selectors-in-puppeteer "Share on LinkedIn")    

 

 

[CSS selectors](https://scrapfly.io/blog/posts/parsing-html-with-css) are one of the most popular ways to parse HTML pages when web scraping. In NodeJS and Puppeteer, CSS selectors can be used through the `page.$` and `page.$$` methods:

javascript```javascript
const puppeteer = require('puppeteer');

async function run() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto("https://httpbin.dev/html");

    // to get the first matching element:
    await page.$("p");
    // to get ALL matching elements:
    await page.$$("p");

    // we can also modify the captured elements immediatly:
    // get the text value:
    await page.$eval("p", element => element.innerText);
    // get attributes attribute:
    await page.$eval("a", element => element.href);

    // same with multiple elements, like count total appearances:
    await page.$$eval("p", elements => elements.length)

    browser.close();
}

run();
```



⚠ It's possible that these commands will try to find elements *before* the page has fully loaded if it's a dynamic javascript page. For more see [How to wait for a page to load in Puppeteer?](https://scrapfly.io/blog/answers/how-to-wait-for-page-to-load-in-puppeteer)

Also see: [How to find elements by XPath in Puppeteer?](https://scrapfly.io/blog/answers/how-to-find-elements-by-xpath-in-puppeteer)



 

    



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-css-selectors-in-puppeteer) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-css-selectors-in-puppeteer) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-css-selectors-in-puppeteer) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-css-selectors-in-puppeteer) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-css-selectors-in-puppeteer) 



 ## Related Articles

 [  

 data-parsing css-selectors 

### Parsing HTML with CSS Selectors

Introduction to using CSS selectors to parse web-scraped content. Best practices, available tools and common challenges ...

 

 ](https://scrapfly.io/blog/posts/parsing-html-with-css) [  

 nodejs headless-browser 

### How to Web Scrape with Puppeteer and NodeJS in 2026

Introduction to using Puppeteer in Nodejs for web scraping dynamic web pages and web apps. Tips and tricks, best practic...

 

 ](https://scrapfly.io/blog/posts/web-scraping-with-puppeteer-and-nodejs) [     

 data-parsing css-selectors 

### Ultimate CSS Selector Cheatsheet for Web Scraping and HTML Parsing

CSS selectors is a powerful HTML querying protocol which is used by browsers to determine what HTML elements to style. I...

 

 ](https://scrapfly.io/blog/posts/css-selector-cheatsheet) 

  ## Related Questions

- [ Q How to find HTML elements by class? ](https://scrapfly.io/blog/answers/how-to-find-html-elements-by-class)
- [ Q How to find HTML elements by multiple tags with BeautifulSoup? ](https://scrapfly.io/blog/answers/how-to-find-html-elements-by-multiple-tags-with-beautifulsoup)
- [ Q How to find elements by XPath in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-find-elements-by-xpath-in-puppeteer)
- [ Q How to find elements by CSS selector in Selenium ](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-in-selenium)
 
  



   



 Run headless browsers at scale, **1,000 free credits** [Start Free](https://scrapfly.io/register)