xPath contains (document.evaulate)
// hack to shove some html on the page since snippet.zone
// quick editor does not yet support HTML :P
document.body.innerHTML += `
<p>This is some text to search...</p>
<p>Here are some random words "Robot, Cat, Swan, Shadow"...</p>
<button>Say Hello Robot</button>
`;
///////////
// find elements with the word `search`
let els = document.evaluate(
"//p[contains(., 'search')]",
document,
null,
XPathResult.ANY_TYPE,
null
);
let el;
while (el = els.iterateNext()) {
console.log('match "search"', el);
}
els = document.evaluate(
"//body/*[contains(., 'Robot')]",
document,
null,
XPathResult.ANY_TYPE,
null
);
while (el = els.iterateNext()) {
console.log('match "Robot"', el);
}
Now that IE is almost dead… we can use xPath – take a look at your console