     [Answers](https://scrapfly.io/blog)   /  [data-parsing](https://scrapfly.io/blog/tag/data-parsing)   /  [How to find elements by XPath in Puppeteer?](https://scrapfly.io/blog/answers/how-to-find-elements-by-xpath-in-puppeteer)   # How to find elements by XPath 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) [\#xpath](https://scrapfly.io/blog/tag/xpath) 

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

 

 

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

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

    // this will always return all found matches as array:
    let elements = await page.$x("//p");

    // to get element details we need to use the evaluate method
    // for text:
    let firstText = await elements[0].evaluate(element => element.textContent);
    console.log(firstText);

    // for other attributes:
    await page.goto("https://httpbin.dev/links/10/1");
    let linkElements = await page.$x("//a");
    let firstLink = await linkElements[0].evaluate(element => element.href);
    console.log(firstLink);

    browser.close();
}

run();
```



⚠ It's possible that this command 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 CSS selector in Puppeteer?](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-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-xpath-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-xpath-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-xpath-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-xpath-in-puppeteer) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-xpath-in-puppeteer) 



 ## Related Articles

 [  

 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) [  

 php 

### Guide to PHP 8.4 new DOM Selector Feature

Learn about PHP 8.4’s new DOM Selector feature. Simplify DOM manipulation using intuitive CSS selectors for cleaner, mor...

 

 ](https://scrapfly.io/blog/posts/php-84-new-dom-selector) [  

 python data-parsing 

### Parsing HTML with Xpath

Introduction to xpath in the context of web-scraping. How to extract data from HTML documents using xpath, best practice...

 

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

  ## Related Questions

- [ Q How to find elements by CSS selectors in Playwright? ](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-in-playwright)
- [ Q How to find elements by XPath selectors in Playwright? ](https://scrapfly.io/blog/answers/how-to-find-elements-by-xpath-in-playwright)
- [ Q How to find elements by CSS selector in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-in-puppeteer)
- [ Q How to wait for a page to load in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-wait-for-page-to-load-in-puppeteer)
 
  



   



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