I need to search for a node using XPath by text contains (inner text)
<div class="row"> // 1-0-4
<div class="col-xs-4">
<label for="FactoryLeadTime">Factory Lead Time:</label>
</div>
<div class="col-xs-8">
4 Weeks
</div>
</div>
My JS code
var xpath = 'label[text()[normalize-space(.)="Factory Lead Time:"]]';
//var xpath = "//label[a[contains(., 'Factory Lead Time:')]]/text()";
var res = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null);
console.log(res);
I am not sure if the search succeed since console shows
XPathResultinvalidIteratorState: falseresultType: 4__proto__: XPathResultPrototype { iterateNext: iterateNext(), snapshotItem: snapshotItem(), ANY_TYPE: 0, … } tmp.js:252:1
In fact i am trying to obtain the result which is "4 Weeks" based on previous text which is "Factory Lead Time:"
Is there a clever way to do this with XPath?
Thanks in advance
Try below XPath to get required poutput:
//div[label="Factory Lead Time:"]/following-sibling::div/text()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With