Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puppeteer: how to wait until an element is visible?

I would like to know if I can tell puppeteer to wait until an element is displayed.

const inputValidate = await page.$('input[value=validate]'); await inputValidate.click()          // I want to do something like that  waitElemenentVisble('.btnNext ')  const btnNext = await page.$('.btnNext'); await btnNext.click(); 

Is there any way I can accomplish this?

like image 604
Pipo Avatar asked Sep 09 '17 23:09

Pipo


People also ask

How do you wait for element in puppeteer?

To wait until an element is visible with Puppeteer and JavaScript, we can use the waitForFunction method. await page.

How do you get the puppeteer element?

We can get element text in Puppeteer. This is done with the help of the textContent property. This property of the element is passed as a parameter to the getProperty method.

How do you use a puppeteer to click a button?

How to click on a button using puppeteer. click() is used to click on any element or button in the puppeteer. the only challenging thing with this is finding the element. Once you got the element just fire the click() function.


1 Answers

I think you can use page.waitForSelector(selector[, options]) function for that purpose.

const puppeteer = require('puppeteer');  puppeteer.launch().then(async browser => {   const page = await browser.newPage();   page     .waitForSelector('#myId')     .then(() => console.log('got it'));     browser.close(); }); 

To check the options avaible, please see the github link.

like image 61
turmuka Avatar answered Sep 18 '22 16:09

turmuka