1

I've a xpath with contains function. I don't know what ., in contains() mean and how does this xpath work? Can anybody please tell me? Thanks.

xpath('//div[label//text()[contains(., "Faculty")]]//input')
techsu
  • 753
  • 2
  • 7
  • 11

2 Answers2

2

. references current context node, which in your case is text node since the . resides in the predicate expression (expression within []) for text(). Break down of your XPath expression :

  • //div[...] : find div elements, anywhere in the document, where...
  • label : the div has child element label
  • //text()[contains(., "Faculty")]: and the label contains descendant text nodes where the value of the text node contains literal 'Faculty'
  • //input: from such div that satisfy all the above criteria, return descendant elements input
kjhughes
  • 106,133
  • 27
  • 181
  • 240
har07
  • 88,338
  • 12
  • 84
  • 137
0

so xpath is //div[label//text()[contains(., "Faculty")]]//input

//div[...]//input searches for all inputs in all divs that matches special condition in brackets

The condition is label//text()[contains(., "Faculty")]

so the above div should have direct child (on 1st level) in which on any level below item with text containing "Faculty" exists

Vitaliy Moskalyuk
  • 2,463
  • 13
  • 15