     [Answers](https://scrapfly.io/blog)   /  [headless-browser](https://scrapfly.io/blog/tag/headless-browser)   /  [How to find elements by XPath in Selenium](https://scrapfly.io/blog/answers/how-to-find-elements-by-xpath-in-selenium)   # How to find elements by XPath in Selenium

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

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-xpath-in-selenium "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. Using Selenium, to find elements by XPath we can use `driver.find_element()` and `driver.find_elements()` methods:

python```python
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://httpbin.dev/html")

element = driver.find_element(By.XPATH, '//p')
# then we can get the element text
print(element.text)
"Availing himself of the mild, summer-cool weather that now reigned in these latitudes..."
# we can also get tag name and attributes:
print(element.tag_name)
print(element.get_attribute("class"))

# for multiple elements we need to iterate
for element in driver.find_elements(By.XPATH, '//p'):
    print(element.text)

driver.close()
```



Also see: [How to find elements by CSS selector in Selenium](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-in-selenium)



 

    



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-selenium) [ 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-selenium) [ 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-selenium) [ 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-selenium) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-find-elements-by-xpath-in-selenium) 



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

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

 python ai 

### Find Web Elements with ChatGPT and XPath or CSS selectors

ChatGPT is becoming a popular assistant in web scraper development. In this article, we'll take a look at how to use it ...

 

 ](https://scrapfly.io/blog/posts/finding-web-selectors-with-chatgpt) 

  ## Related Questions

- [ Q How to find elements by CSS selector in Selenium ](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-in-selenium)
- [ Q How to save and load cookies in Selenium? ](https://scrapfly.io/blog/answers/how-to-save-and-load-cookies-in-selenium)
- [ Q How to take a screenshot with Selenium? ](https://scrapfly.io/blog/answers/how-to-take-screenshot-with-selenium)
- [ Q How to find elements by CSS selectors in Playwright? ](https://scrapfly.io/blog/answers/how-to-find-elements-by-css-selectors-in-playwright)
 
  



   



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