     [Answers](https://scrapfly.io/blog)   /  [data-parsing](https://scrapfly.io/blog/tag/data-parsing)   /  [How to select elements by text in XPath?](https://scrapfly.io/blog/answers/how-to-select-elements-by-text-in-xpath)   # How to select elements by text in XPath?

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

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

 

 

To select elements by text using XPath we can either match the `text()` value or use it in a `contains()` function.
For example, to select `<a>websites</a>` we would use `//a[contains(text(), "website")]` selector. See this interactive example:

&lt;html&gt; &lt;a&gt;ignore&lt;/a&gt; &lt;a&gt;website&lt;/a&gt; &lt;a&gt;WEBSITE&lt;/a&gt; &lt;/html&gt; Note that `contains()` method is **case sensitive**.
For case-insensitive selections we can use `matches` (sometimes called `re:test()`) function:

&lt;html&gt; &lt;a&gt;ignore&lt;/a&gt; &lt;a&gt;website&lt;/a&gt; &lt;a&gt;WEBSITE&lt;/a&gt; &lt;/html&gt; 

 

    



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-select-elements-by-text-in-xpath) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-text-in-xpath) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-text-in-xpath) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-text-in-xpath) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-text-in-xpath) 



 ## Related Articles

 [  

 data-parsing xpath 

### Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

Ultimate companion for HTML parsing using XPath selectors. This cheatsheet contains all syntax explanations with interac...

 

 ](https://scrapfly.io/blog/posts/xpath-cheatsheet) [  

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

 blocking tools 

### How Browser Fingerprinting Works and How to Defend Against It

Learn how browser fingerprinting works, from canvas to WebGPU, and discover developer-focused techniques to bypass detec...

 

 ](https://scrapfly.io/blog/posts/how-browser-fingerprinting-works) 

  ## Related Questions

- [ Q How to find HTML elements by text value with BeautifulSoup ](https://scrapfly.io/blog/answers/how-to-find-html-elements-by-text-with-beautifulsoup)
- [ Q How to find elements without a specific attribute in BeautifulSoup? ](https://scrapfly.io/blog/answers/how-to-find-elements-without-attribute-in-beautifulsoup)
- [ Q How to select elements by class in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-by-class-in-xpath)
- [ Q How to select elements by ID in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-by-id-in-xpath)
 
  



   



 Extract structured data with AI, **1,000 free credits** [Start Free](https://scrapfly.io/register)