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')
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')
.
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
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