Selenium Tips

XPath - Cheat Sheet


  • . //TagName[@AttributeName='AttributeValue']

Example:

Find 'Family Name' with name attribute

.//input[@name='Family Name']

Find button with id

.//input[@id='submit']

  • .//TagName[@AttributeName='AttributeValue'][@AttributeName='AttributeValue']

Example:

.//input[@name='submit'][@type='button']

.//input[@name='search'][@type='input']


  • .//TagName[@AttributeName='AttributeValue' and @AttributeName='AttributeValue']

Example:

.//input[@name='submit' and @type='button']

.//input[@name='search' and @type='input']

  • . //TagName[@AttributeName='AttributeValue' or @AttributeName='AttributeValue']

Example:

.//input[@name='submit' or @type='button']

.//input[@name='search' or @type='input']

  • .//TagName[@AttributeName='AttributeValue']/TagName[n]/TagName[n]

Example:

Find input field after 'Family Name'.

.//input[@name='Family Name']/div[1]/input[0]