I am using Puppeteer to reach a button (unfollow button) in my GitHub followings page. Because this button does not exist when I scrape this page I think it has been created by user-side JS code. Then I used waitForSelector
command in order to wait for this button, but again page could not find the button. Here is my code:
const test2=async()=>{
let url='https://github.com/nariman?tab=following'
await browserInit()
await page.goto(url)
await page.waitForSelector('input.btn')
console.log('done')
}
and it will cause this error:
TimeoutError: Waiting for selector `input.btn` failed: Waiting failed: 30000ms exceeded
You can test it in your own GitHub page. Is there any solution?
2
Answers
you can use something called MutationObserver like page.on(‘mutationover’,callback) by using which you can monitor DOM changes and wait specifically for the unfollow button insertion
use timeout delay instead of waiting for a selector. It is a crutch but works fine for me. Also make sure your selector is not inside of the iframe