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.