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?
To wait until an element is visible with Puppeteer and JavaScript, we can use the waitForFunction method. await page.
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 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With