[go: up one dir, main page]

0% found this document useful (0 votes)
245 views1 page

XPath Cheat Sheet v1.1

This document provides a summary of different types of XPath patterns for selecting elements in XML documents. It describes relative XPath patterns based on attributes, text, partial attributes, and partial text. It also covers XPath patterns based on collections using item indexes and child item indexes. Finally, it discusses XPath patterns using axes to select younger and elder siblings as well as younger and elder cousins.

Uploaded by

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

XPath Cheat Sheet v1.1

This document provides a summary of different types of XPath patterns for selecting elements in XML documents. It describes relative XPath patterns based on attributes, text, partial attributes, and partial text. It also covers XPath patterns based on collections using item indexes and child item indexes. Finally, it discusses XPath patterns using axes to select younger and elder siblings as well as younger and elder cousins.

Uploaded by

ARK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

TEEHSTAEHC HTAPX

RELATIVE PARENT - CHILD


XPath pattern based on the XPath pattern based on the
attribute / text (grand) parent to (grand)
child relationships
ATTRIBUTE
//tagName[@attibute='value']
PARENT TO CHILD
(xpath of parent)/child-tagName
TEXT
//tagName[text()='value']
CHILD TO PARENT
(xpath of child)/parent::parent-tagName
PARTIAL ATTRIBUTE
//tagName[contains(@attibute,'value')]
CHILD TO GRAND PARENT
(xpath of child)/ancestor::ancestor-tagName

PARTIAL TEXT
//tagName[contains(text(),'value')]
GRAND PARENT TO CHILD
(xpath of ancestor)//child-tagName

LAST CHILD
(xpath of parent)/child-tagName[last()]

COLLECTION
XPath pattern based on the
indexes with(out) relations.
Note: index starts at 1
AXES
USING ITEM INDEX XPath pattern based on the
(xpath)[index] sibling & Cousin relatiionships

USING CHILD ITEM INDEX YOUNGER SIBLING


(parent-xpath)/child-tagName[index] (xpath)/following-sibling::sibling-tagName

USING AND CONDITION ELDER SIBLING


//tagName[@att1='v1' and @att2='v2'] (xpath)/preceding-sibling::sibling-tagName

USING OR CONDITION
//tagName[@att1='v1' or @att2='v2'] YOUNGER COUSIN
(xpath)/following::cousin-tagName

ELDER COUSIN
(xpath)/preceding::cousin-tagName

Use Ruto, the opensource xpath


finder if you find difficult to write
your own xpaths.

It is available as Chrome, Firefox,


www.testleaf.com
Edge extensions

You might also like