0

At some places, I saw element like following -

//a[.='Assignment']

Generally we've syntax like - //tagName[attributeKey='attributeValue'] or //tagName[text()='textValue']

But what is intention of . in xpath //a[.='Assignment']?

Alpha
  • 13,320
  • 27
  • 96
  • 163
  • 3
    Possible duplicate of [XPath: difference between dot and text()](https://stackoverflow.com/questions/38240763/xpath-difference-between-dot-and-text) – Andersson Jul 10 '18 at 07:44

1 Answers1

0

I'll use XPath 2.0 terminology here: XPath 1.0 has different terminology but the effect of the expression is the same.

"." refers to the context item: that is, the a element that you are testing against the predicate. Its value here is a node. When a node is used as an argument of "=", it is atomized, which means (unless your code is schema-aware, which is unlikely) that the string value of the node is compared with the other operand of "=". The string value of an element is the concatenation of all its descendant text nodes.

It sounds like you don't have ready access to an XPath reference. There are quite a few good books that cover XPath, there are online tutorials (which are highly variable in quality) and the W3C specification itself (especially for XPath 1.0) is surprisingly easy reading.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164