XPath Cannot locate element using text() -
following code:
<label> <input class="class1" type="checkbox" checked="checked"/> first text </label> <label> <input class="class2" type="checkbox" checked="checked"/> second text </label> <label> <input class="class3" type="checkbox" checked="checked"/> third text </label> what want specific label element containing text. trying:
//label[text()='first text'] and
//label[contains(text(),'first text')] but doesnt work.
please, advise!
thanks! :)
//label[text()[contains(., 'first text')]]
your attempt
//label[contains(text(),'first text')]
does not work because <label> in
<label>[ ]<input class="class1" type="checkbox" checked="checked"/>[ first text ]</label> has two text nodes: empty 1 containing nothing line break, right before input, , non-empty 1 after <input>. i've outlined them square brackets above.
- a call
contains(node-set, string)forces conversion of first argumentcontainsstring. - converting node-set string gives text content of first node of set. (try out,
string(label)give'first text'bunch of whitespace, no matter how many labels there are.) - and in case, that's empty text node,
contains(text(),'first text')never succeed.
therefore must test text nodes individually, , that's done nesting predicates shown above.
Comments
Post a Comment