in puppeteer I would like to wait a defined time before going to the next line of code.
I've tried to put a setTimeout
in an evaluate function but it seems to be simply ignored
console.log('before waiting');
await page.evaluate(async() => {
setTimeout(function(){
console.log('waiting');
}, 4000)
});
console.log('after waiting');
This code don't wait and just write before waiting and after waiting
Do you know how to do this?
I've been using:
Where 3000 is Milliseconds And that seems to be working for me.
Your syntax is incomplete.
Try this...
You can use a little promise function,
Then, call it whenever you want a delay.
If you must use puppeteer use the builtin waitFor function.
If you still want to use page.evaluate, resolve it after 4 seconds. You are not resolving anything.
But I guess you can simply use the first two examples.
Try this function.
to use it
You can use one of the following options to wait for one second:
Alternatively, there are many Puppeteer functions that include a built-in
delay
option, which may come in handy for waiting between certain events: