Sunday, August 3, 2014

Custom XPath Creation Technique

Mainly we use FirePath for getting XPath of an element but sometime we need to make XPath manually or need to customize the XPath.

Some Basic of XPath Notation

Select from the root node                   
ex: html/body/.......

Select nodes form the current node     
ex: //table/tbody/tr/.............

Select attribute                                  
ex: //input[@id='abc']

//input[@id='Some Value']          
Select element with tag name and id        

Select element with text containing abc
ex: //input[contains(text(),'abc')]

Select element with text starting with abc
ex: //input[starts-with(text(),'abc')]

//input[contains(@id, 'TextValue')]    
identify element containing 'abc' in value attribute

//input[contains(@id, 'searchInput') and contains(@text,'google')]
look at two attributes in input node

//input[starts-with(@type, 'abc')]
find input node with attribute type and its value is starting with 'abc'

Can use wild cards

Select element with tag input and text=abc

Find all elements containing 'abc'

Select Input of First Position

Select 2nd div of the div node One thing keep in mind that descendant means child, child of child etc


ancestor-or-self means traversing starts from current node.


Select span text

Select div that does not contain any child node