     [Answers](https://scrapfly.io/blog)   /  [xpath](https://scrapfly.io/blog/tag/xpath)   /  [How to select element with one of many names in XPath?](https://scrapfly.io/blog/answers/how-to-select-elements-by-attribute-value-in-xpath)   # How to select element with one of many names in XPath?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Apr 18, 2026 2 min read [\#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-attribute-value-in-xpath "Share on LinkedIn")    

 

 

The XPath syntax allows interaction with web elements' attributes, such as `class`, `id`, `href`, and others, through the `@` XPath expression. This enables us to select any element in the web page DOM based on its attribute values with XPath selectors. To select elements based on their attribute values, we can follow either of two XPath expressions:

- Select the desired element by its exact attribute value, such as `[@attribute='value']`
- Select by partial attribute value using XPath contains, such as `[contains(@attribute, 'value')]`

Let's go over practical examples of applying the above XPath queries to extract data on both HTML and XML documents.

### Using XPath @ expression

The `@` XPath expression selects a web element using the exact element's attribute:

&lt;!-- select all links by selecting the @href attributes --&gt; &lt;html&gt; &lt;a href="/categories/1"&gt;category&lt;/a&gt; &lt;a href="/product/1"&gt;product 1&lt;/a&gt; &lt;a href="/product/2"&gt;product 2&lt;/a&gt; &lt;a href="/product/3"&gt;product 3&lt;/a&gt; &lt;/html&gt; Here, we use the XPath query to select all elements containing the `href` tag.

### Using XPath contains expression

The `contains` XPath function enables selecting a particular web element based on its partial text match:

&lt;!-- select only product links by checking @href attribute --&gt; &lt;html&gt; &lt;a href="/categories/1"&gt;category&lt;/a&gt; &lt;a href="/product/1"&gt;product 1&lt;/a&gt; &lt;a href="/product/2"&gt;product 2&lt;/a&gt; &lt;a href="/product/3"&gt;product 3&lt;/a&gt; &lt;/html&gt; Above, we select all `href` attributes by using a partial text search. For further details on XPath selectors, refer to our dedicated guide.

[Parsing HTML with XpathIntroduction to xpath in the context of web-scraping. How to extract data from HTML documents using xpath, best practices and available tools.](https://scrapfly.io/blog/posts/parsing-html-with-xpath)

## XML

Note that the mentioned XPath functions can also be applied with the XML path language. Here's an example of parsing an XML document:

&lt;product&gt; &lt;variant&gt; &lt;price&gt;99$&lt;/price&gt; &lt;rate type="product A"&gt;4.5&lt;/rate&gt; &lt;/variant&gt; &lt;variant&gt; &lt;price&gt;120$&lt;/price&gt; &lt;rate type="product B"&gt;3.5&lt;/rate&gt; &lt;/variant&gt; &lt;/product&gt; We can also use the XPath `contains` expression to text by partial attribute text:

&lt;product&gt; &lt;variant&gt; &lt;price&gt;99$&lt;/price&gt; &lt;rate type="product A"&gt;4.5&lt;/rate&gt; &lt;/variant&gt; &lt;variant&gt; &lt;price&gt;120$&lt;/price&gt; &lt;rate type="product B"&gt;3.5&lt;/rate&gt; &lt;/variant&gt; &lt;/product&gt; For more on parsing XML with XPath and CSS selectors, refer to our dedicated guide.

[How to Parse XMLIn this article, we'll explain about XML parsing. We'll start by defining XML files, their format and how to navigate them for data extraction.](https://scrapfly.io/blog/posts/how-to-parse-xml)



 

   Table of Contents















 

  Table of Contents- [Using XPath @ expression](#using-xpath-expression)
- [Using XPath contains expression](#using-xpath-contains-expression)
- [XML](#xml)
 
    Join the Newsletter  Get monthly web scraping insights 

 

  



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



 ## Related Articles

 [  

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

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

 api 

### Guide to Google News API and Alternatives

In a world of endless information, accessing news data efficiently can be vital for many businesses. Google News has bee...

 

 ](https://scrapfly.io/blog/posts/guide-to-google-news-api-and-alternatives) 

  ## Related Questions

- [ Q How to get the name of an HTML element in XPath? ](https://scrapfly.io/blog/answers/how-to-get-name-of-selected-element-in-xpath)
- [ Q How to select any element using wildcard in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-of-any-name-using-wildcards-in-xpath)
- [ Q How to select last element in XPath? ](https://scrapfly.io/blog/answers/how-to-select-last-element-in-xpath)
- [ Q How to select elements by class in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-by-class-in-xpath)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)