Puppeteer: Get innerHTML

Noah picture Noah · Sep 26, 2017 · Viewed 29.6k times · Source

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!

Answer

Ryan picture Ryan · Oct 4, 2017

This is how i get innerHTML:

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