'TimeoutError: waiting for selector '--selector--' failed: timeout 30000ms exceeded

If I run code without 'waitForSelector' it gives 'null' and when I run it with 'waitForSelector' it gives time exceeded error. I already have tried giving custom value for timeout but still the problem persist.

error: Timeout or other error: TimeoutError: waiting for selector [class*="header-content"] span:nth-child(2) failed: timeout 30000ms exceeded

Output needed: '1 views'

Code:


const viewsData = async () => {   
  const browser = await puppeteer.launch()   
  const page = await browser.newPage()    
  await page.goto("https://www.loom.com/share/5b920dc1375f43fa9b622ac0a6ba7c52")   
  await page    
    .waitForSelector(`[class*="header-content"] span:nth-child(2)`)   
    .then(() => {  
      console.log("Success")   
    })   
    .catch((err) => {    
      console.log("Timeout or other error: ", err)   
    })    
  let re = await page.evaluate(() => document.querySelector(`[class*="header-content"] span:nth-child(2)`))   
  console.log(re)    
  await browser.close()   
}    
viewsData()



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source