How to use contains to get the attribute value in xpath 

This is one my best finds so far and would like to share it with you. Here is an example that shows you how to use the xpath contains to build a xpath using part of the attribute value. This can be used when there are elements with the same id or text value.

Here is the source code of the page

Edit
Delete

Now I would like to build the xpath of the Edit link.
//a[contains(@href,'CustomerContacts')][.='Edit']


Author: Pavandeep Puddupakkam on November 19, 2010
Category: XPath
Tags:
Google Webdriver Forum -The Online Community for Google Webdriver and Selenium RC Users and Professionals
5 responses to “How to use contains to get the attribute value in xpath”
  1. Sam says:

    You can also build the xpath use this syntax
    /a[@href[contains(.,'CustomerContacts')]]

  2. Kuntal says:

    Thanks Sam.
    The info was useful

  3. [...] using Ruby code Selenium RC with Java and JUnit Sample Selenium RC Script using TestNG Eclipse How to use contains to get the attribute value in xpath Author: Pavandeep Puddupakkam on March 5, 2011 Category: Selenium RC Tags: [...]

Leave a Reply

Last articles