Search code examples
javascriptnode.jsseleniumwebautomationpuppeteer

Puppeteer: Get innerHTML


Does anybody know how to get the innerHTML or text of an element? Or even better; how to click an element with a specific innerHTML? This is how it would work with normal JavaScript:

var found = false
$(selector).each(function() {
    if (found) return;
    else if ($(this).text().replace(/[^0-9]/g, '') === '5' {
        $(this).trigger('click');
        found = true
    }
});

Thanks in advance for any help!


Solution

  • This is how i get innerHTML:

    page.$eval(selector, (element) => {
      return element.innerHTML
    })