0% found this document useful (0 votes)
34 views2 pages

Day25-Xpath AxisLocators

The document provides a comprehensive guide on using XPath to locate various elements in an XML document, including parent, child, ancestor, descendant, following, and preceding elements. It includes syntax examples for each type of element location, demonstrating how to construct XPath queries effectively. The document serves as a reference for understanding the hierarchical relationships between elements in XML structures.

Uploaded by

ϻohammed Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Day25-Xpath AxisLocators

The document provides a comprehensive guide on using XPath to locate various elements in an XML document, including parent, child, ancestor, descendant, following, and preceding elements. It includes syntax examples for each type of element location, demonstrating how to construct XPath queries effectively. The document serves as a reference for understanding the hierarchical relationships between elements in XML structures.

Uploaded by

ϻohammed Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Day 25

-----------
1[ANCESTER::]
2 4[parent::]
3
[preceding sibling::]5 6[self] 7[Following sibling::]
7 8 9 [child]
10[descendent::]

Locating parent element


---------------------------
systax
//knownXpath/parent::elementName
//knownXpath/parent::*
//knownXpath/..

//input[@id="small-searchterms"]/parent::form

ex:
//input[@id='txtUsername']/parent::form
//input[@id='txtUsername']/parent::*
//input[@id='txtUsername']/..

locating child element


---------------------------
//XpathOfContextElement/child::elementName
//XpathOfContextElement/child::*
//XpathOfContextElement/elementName

Ex:
//div[@id='divUUsername']/child::span
//div[@id='divUUsername']/span

locating grand Childern


---------------------------
//XpathOfContextElement/*/elementName
//XpathOfContextElement/childName/elementName

Ex:
//form/div/input
//form/*/input

Locating ancestor
---------------------------
//XpathOfContextElement/ancestor::elementName
//XpathOfContextElement/ancestor::*

Ex:
//input[@id='txtUsername']/ancestor:form
//input[@id='txtUsername']/ancestor:*

Locating descendent element


---------------------------
//XpathOfContextElement/descendent::elementName
//XpathOfContextElement/descendent::*
Ex:
//form[@id='frmLogin']/decendent::input
//form[@id='frmLogin']//input

Locating following
---------------------------
////XpathOfContextElement/following::elementName
////XpathOfContextElement/following::*

Ex:
//input[@id='txtUsername']/following::input
//input[@id='txtUsername']/following::*

//input[@id='txtUsername']/following::input[last()]
//input[@id='txtUsername']/following::input[2]

Locating preceding
---------------------------
////XpathOfContextElement/preceding::elementName
////XpathOfContextElement/preceding::*

Ex:
//input[@id='txtUsername']/preceding::input
//input[@id='txtUsername']/preceding::*

//input[@id='txtUsername']/preceding::input[2]

Locating following sibling


---------------------------
////XpathOfContextElement/following-sibling::elementName
////XpathOfContextElement/following-sibling::*

Ex:
//input[@id='txtUsername']/following-sibling::input
//input[@id='txtUsername']/following-sibling::*

//input[@id='txtUsername']/following-sibling::input[last()]
//input[@id='txtUsername']/following-sibling::input[2]

Locating preceding sibling


---------------------------
////XpathOfContextElement/preceding-sibling::elementName
////XpathOfContextElement/preceding-sibling::*

Ex:
//input[@id='txtUsername']/preceding-sibling::input
//input[@id='txtUsername']/preceding-sibling::*

You might also like