I'm trying to find an element based on the text inside. For example, to find this link:
<a href="#">Foobar</a>
Using the codes below I get null
on console.log(matchingElement)
in both cases
var xpath = "a[text()='Foobar']";
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
console.log(matchingElement);
xpath = "a[contains(text(),'Foobar')]";
matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
console.log(matchingElement);
<a href="#">Foobar</a>