What does a double-slash used twice in an XPath selector mean?
Suppose I'm using a path like:
//div[@id='add']//span[@id=addone']
Double Slash “//” – Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document.
The double slash is a comment. Triple slash doesn't mean anything special, but it might be a comment that was added right before a division.
Two backslashes are used as a prefix to a server name (hostname). For example, \\a5\c\expenses is the path to the EXPENSES folder on the C: drive on server A5. See UNC, \\, path and forward slash.
Difference between “/” and “//” in XPathSingle slash is used to create absolute XPath whereas Double slash is used to create relative XPath. 2. Single slash selects an element from the root node. For example, /html will select the root HTML element.
A double slash "//
" means any descendant node of the current node in the HTML tree which matches the locator.
A single slash "/
" means a node which is a direct child of the current.
//div[@id='add']//span[@id=addone']
will match:
<div id="add"> <div> <span id="addone"> </div> </div>
And:
<div id="add"> <span id="addone"> </div>
//div[@id='add']/span[@id=addone']
will match only the second HTML tree.
Double slash (//
) is the descendant-or-self axis; it is short for /descendant-or-self::node()/
.
In your example XPath:
//div[@id='add']//span[@id='addone']
//
appears, it selects all div
elements in the document with an id
attribute value equal to 'add'
.//
appears, it selects all span
elements that are descendents of each of the div
elements selected previously.//span[@id='addone']
would select all span
elements with @id='addone'
in the entire document, regardless of whether they are a descendent of a div
with @id='add'
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With