0

Website. I am trying to get access to the claimed in this website using puppeteer. the claimed is an h4 a child of a div with class "planet-desktop_planetContainer_v6lY1". Which is also a child of div. A total makes a 7 divs then a body element.

 const heading4 = await page.$eval("planet-desktop_planetContainer_v6lY1 > h4", el => el.textContent);
     console.log(heading4)

  const n = await page.$("[class='planet-details-desktop_planetHeading_2ski7']")
  const t = await (await n.getProperty('textContent')).jsonValue()   
  console.log(t)
  const elements = await page.$$("h4");
    elements.forEach(async element => {
        const text = await (await element.getProperty("innerText")).jsonValue();
        console.log(text);
    });

I tried all of them and none of them returned the child h4

Pradeep Kumar
  • 1,193
  • 1
  • 9
  • 21
  • It works fine if I run headfully and use `page.waitForSelector()` to wait for the element to appear, but fails headlessly even with a user agent, so I think this reduces to [Why does headless need to be false for Puppeteer to work?](https://stackoverflow.com/questions/63818869/why-does-headless-need-to-be-false-for-puppeteer-to-work). – ggorlen Dec 03 '22 at 15:25
  • how can i use waitforselector()? – Hafeez Ali Dec 03 '22 at 15:59
  • Check the docs: [`const el = await page.waitForSelector(yourSelector)`](https://pptr.dev/api/puppeteer.page.waitforselector/). For pages that generate content dynamically, this is pretty much essential. `page.$` just grabs immediately and gives up if nothing is there, which is the case here when the page initially loads. – ggorlen Dec 03 '22 at 15:59

0 Answers0