Reputation: 9407
I have the following markup:
<span id="lbl_partyType" style="color:DarkBlue;">DEFENDANT
<span style="color:darkblue;">(<b>PRIMARY</b>)</span></span>
I want to target that span by the text "DEFENDANT". I want to use xpath in JavaScript to do this. I tried the following:
var xpath = "span[text()='DEFENDANT']";;
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
matchingElement is null. What is wrong with my xpath that it is not finding the element?
Upvotes: 2
Views: 63
Reputation: 56162
This one should work:
//span[contains(text(), 'DEFENDANT')]
Upvotes: 1