From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Handling dialogs

Handling dialogs

In the previous lesson, we learned about how can we register event listener for different events and in this lesson, we'll see how can we listen to dialogue events. Now one thing before I proceed, that is we will learn how to handle the alert, the confirm and the prompt events, which is using just the JavaScript functions. Now these are pretty old and most of the website does not use them, instead they use custom styled dialog boxes. But anyway, we'll learn how to handle these elements. Now Playwright automatically does that for us. That is, if I click on this alert box, you can see a alert like this. I'm sure you would not have seen something like this in any modern website. But Playwright goes ahead and clicks this OK button for us. Now to show you the same, let's go ahead and pull this in. You'll find the link to this test site in the resources. So first of all, we'll go ahead and select this button. And if I inspect the same, you can see it is a input element with some attribute…

Contents