1

I've been attempting to do some web scraping using puppeteer, and I've run into the following problem: enter image description here I want to click an element that has a specific inner text (in this case 'INHERITANCE TAX RETURN'), but everything else about the element seems to be identical to a lot of other elements on the page. I was wondering if anyone knew a way to search for an element based on its inner text. Any help would be greatly appreciated.

Nicholas Jennings
  • 201
  • 2
  • 3
  • 8
  • 2
    Possible duplicate: https://stackoverflow.com/questions/47407791/puppeteer-click-on-element-with-text – Antonio Narkevich Jun 04 '18 at 08:41
  • 2
    Possible duplicate of [Puppeteer: Click on element with text](https://stackoverflow.com/questions/47407791/puppeteer-click-on-element-with-text) – Vaviloff Jun 04 '18 at 09:28

1 Answers1

4

Have you tried:

const linkHandlers = await page.$x("//span[contains(text(), 'INHERITANCE TAX RETURN')]");
if (linkHandlers.length > 0) {
  await linkHandlers[0].click();
} else {
  throw new Error("Link not found");
}
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225