How can I run a custom js function in playwright? For example show an alert. I have already tried this way but it did not work.
var url = await page.evaluate(async() => {
await function alert() {
alert("alert");
}
await alert();
});
You would just do:
await page.evaluate(() => alert("alert"))
But keep in mind, that alert's are blocking in the JavaScript browser world and dismissed automatically by Playwright. See here how to interact with them (dismiss e.g.)
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