0% found this document useful (0 votes)
31 views

XPATH Rules 1

The document discusses different XPath expressions and operators. It explains how asterisk and node() are used as wildcards and how absolute and relative paths differ. It also covers the use of operators like or and | and functions like text(), contains() and node().

Uploaded by

Zishan Ahamed
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)
31 views

XPATH Rules 1

The document discusses different XPath expressions and operators. It explains how asterisk and node() are used as wildcards and how absolute and relative paths differ. It also covers the use of operators like or and | and functions like text(), contains() and node().

Uploaded by

Zishan Ahamed
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/ 3

//html/body

//html/*[2] select body tag


//html//p[@id]

* Or node() is wild card xpath


* means represent any tags
/html/head
/html/*
/*/* html child
/*/*/* Grand child of html

/html/body/p[@id]
/html/body/p[@*]

/html vs //html
//* vs //*[@*] as html tag also have some attributes

Conversion of absolute to relative


/html/body/p this is absolute
//html/p this is relative
//node()/p any node means html head title body p input etc.
<html>
<head>
<title> </title>
</head>
<body>
<p> </p>
<p> </p>
</body>
</html>

To go to p need /html/body/p or //html/p or //p

Asterisk * or wild cards used to represent any tag and any attributes
Node () used to represent only any tags

/html/body/p in node is node ()/node ()/p which also same as /*/*/p


Node () is replaceable with asterisk symbol /*/node ()/p

1. Asterisk is the most used wild cards in X- Path and node () is least used
2. Asterisk represents any tags and any attributes. But node() represent only any tag
3. Node () can be replaced with asterisk.
4. At the end of X-Path expression you cannot used the node() like this, /html/body/node()
5. Don’t used node () in real time as needs least time.

//table/tbody/tr
//table//tr direct/shortcut

When to use or and | operator?


Same tag name but search for different attribute then used or
Same tag name but wants data from two different tags within same tag. Used | operate. For example table tag for th
and td data.

Text () cannot be used in those tag have no text like input, li


Shortcut of text () is dot (.)
To match text must also take consider the spaces in text?
Need to provide whole text including spaces in text () x-path function.

Contains () partial text enough than complete text


Contains used in real time is where id is frequently changes like 123QA456 to 777QA456
//input[contains(@id,’QA’)]

Text() does not support attribute values where contains() and start-with() supports

You might also like