0

Recently I came across an XPath locator value which has "/../" in between.

What is the meaning of it?

Context XPath:

//*[contains(@class, 'xyz')]//*[contains(text(), 'text')]
                            /../*[contains(@class, 'className')]
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Praveen Somayaji
  • 47
  • 1
  • 1
  • 9
  • 1
    `/..` means *go to one level up in DOM (returns the parent node of the node with text `'text'`)*. Next slash means *return the child with `@class` `'className"`*. Note that nodes with text `'text'` and with `@class` `'className'` might be siblings or it might be the same node – Andersson Jun 07 '18 at 11:57
  • ok got it. Thank you so much. – Praveen Somayaji Jun 07 '18 at 13:10
  • I prefere to use such xpath: //*[contains(@class, 'xyz')]//*[contains(@class, 'className')][./*[contains(text(), 'text')]] – Vitaliy Moskalyuk Jun 07 '18 at 14:50

1 Answers1

3

/../ in XPath1

Relatively, /../node() selects the parent's children of the context node:

  • / separates location steps.
  • /.. selects the parents of the context node because .. is an abbreviation for parent::.
  • /../ introduces an incomplete next step.
  • /../node() would select the parent's children nodes.

Absolutely, /../node() selects nothing.

  • / selects the root node.
  • /.. selects nothing because the root node has no parent.
  • /../ introduces an incomplete next step.
  • /../node() would select nothing because /.. selected nothing.

1. Note that by itself, /../ is syntactically invalid; below assumes its part of a valid XPath.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • @MichaelKupietz: No, it's **absolute** if it *starts* the XPath; otherwise, it's **relative**. See also [What is the difference between root node, root element and document element in XML?](https://stackoverflow.com/q/51025654/290085) – kjhughes Apr 06 '19 at 18:41
  • Sorry, I accidentally deleted my above comment trying to edit it, I didn't see you had answered already. So, then, here's a question: on https://bytes.com/topic/net/answers/85603-using-xslt-xpath-graph-data-structure-processing, @Dimitre-Novatchev has a solution that uses . Is that just a fancy way of saying "set the parameter to nothing by default"? Thanks, by the way. This is all pretty confusing for a procedural programmer. – John Smith Apr 06 '19 at 18:55
  • Basically, but feel free to ask a new question for further details. Comments aren't intended for new questions or extended dialog. And don't be discouraged by unfamiliarity. If you push through it, you'll find familiarity with multiple paradigms to be an asset. – kjhughes Apr 06 '19 at 19:07