Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puppeteer wait for element disappear or remove from DOM

Is there any way or Puppeteer API we can wait element to disappear or remove from Dom and then continue the execution?

E.g I have a loading animation I want to wait until this loading animation remove from Dom.

like image 259
Mehran Shafqat Avatar asked Nov 13 '19 09:11

Mehran Shafqat


2 Answers

waitForSelector has a hidden option which also check if the element is in the DOM:

await page.waitForSelector('div', {hidden: true});
like image 169
hardkoded Avatar answered Sep 23 '22 06:09

hardkoded


Try this

await page.waitFor(() => !document.querySelector(querySelector));

or even the waitForFunction()

await page.waitForFunction()
like image 32
dev_Fares Avatar answered Sep 21 '22 06:09

dev_Fares