I'm using Typescript for Puppeteer. I'm trying to get innerText from an element.
const data = await page.$eval(selector, node => node.innerText);
I'm getting the error:
Property 'innerText' does not exist on type 'Element'
I tried casting to HTMLElement like described in this question: error " Property 'innerText' does not exist on type 'EventTarget' "?
const data = await page.$eval(selector, <HTMLElement>(node: HTMLElement) => node.innerText);
As well as creating my own Interface like this:
interface TextElement extends Element {
innerText: string;
}
But in each case I'm getting the error that innerText does not exist on this particular type.
Property 'innerText' does not exist on type 'HTMLElement'
Why is this happening and how to deal with this?
textContent
instead? – CertainPerformanceawait page.evaluate(() => document.querySelector("your_selector").innerText)
Before trying execute in console thisdocument.querySelector("your_selector").innerText
to check whether you're getting the required result. – PySaadinnerText
may sometimes be preferable totextContent
if there are child elements and whitespace in the mix. perfectionkills.com/the-poor-misunderstood-innerText – simmer