Using Puppeteer to Retrieve and Act on innerHTML

I’m working with Puppeteer and need assistance with extracting an element’s innerHTML or its text content. More specifically, I’m looking to programmatically click an element that has a particular innerHTML. In plain JavaScript, I implemented a method that iterates over elements, searches for specific text content, and clicks the matching element. Below is an example of a similar approach in vanilla JavaScript for clarity:

let wasClicked = false;
const elements = document.querySelectorAll('.item');

elements.forEach( (elem) => {
    if (wasClicked) return;
    const cleanedText = elem.textContent.replace(/\D/g, '');
    if (cleanedText === '5') {
        elem.click();
        wasClicked = true;
    }
});

Any advice on replicating or refining this behavior through Puppeteer would be greatly appreciated.

hey finn, try using page.evaluate to get all elemnts and then click on the right one. i had luck filtering via textContent inside that eval. hope that help’s you out!