XPATH: button contains text

Last updated on:

1. Element contains

//button[contains(.,'Submit')]

Here is an example with Google Home Page:

//input[@value='Google Search']

You can read as: find "input" field where "value" equal to "Google Search"
I found out that snippets bellow works better in my current project:

2. Element with attribute and contains

//button[@type='button' and contains(., "Submit")]

3. Get child element

For example here is and simple html

To get all child div containers you could use xpath like the one below:

//div[contains(@class,'cities')]/child::div

And then let say you want to select one specific child div container, here is how you do it:

//div[contains(@class,'cities')]/child::div[1]

4. Locate parent element

//div[contains(@class,'x-grid3-row-first')]/parent::div

W3 xpath reference

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.