XPath functions.

1. Single attribute


Double attribute


2. Parent


3. Ancestor


4. Child


5. Descendant


6. Following



7. Preceding



8. index based





9. Text value




//span[contains (.,’CONTINUE’)]


10. And/Or

//input[@type=’submit’ or @name=’btnReset’]

//input[@type=’submit’ and @name=’btnLogin’


XPath and cssSelector Error Handling


1. //svg is the wrong format. SVG elements doesn’t support the standard xpath format. It has a different format.

wrong format – //svg

correct format for svg-


and for svg child- Suppose path tag is the child element of svg then the format will be

wrong format- //path

correct format – //*[name()=’path’]

2. Shadow DOM elements don’t support xpath so we can write only cssSelector for shadow DOM elements.
3. After / only tagname * and . is allowed
wrong xpath – //li-icon[@type=’camera-icon’]/../*/

correct format- //li-icon[@type=’camera-icon’]/../*/div

4. Just after ] text is not allowed.
wrong format – //li-icon[@type=’camera-icon’]div
correct format – //li-icon[@type=’camera-icon’]//div


cssSelector function





tagName[attributeName$=’ending value of attributeValue’]

tagName[attributeName^=’starting value of attributeValue’]

tagName[attributeName*=’substring of attributeValue’]

$ – ends with 

^ – starts with 

* – contains