From the course: Test Automation with Selenium WebDriver for Java

Unlock this course with a free trial

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

Modals

Modals

- [Instructor] A modal is a popup window that when displayed, deactivates all other content on the page. Let's use Selenium WebDriver to engage with this modal. After clicking the button that triggers the modal, let's check if the modal is actually displayed. First, we'll find the modal by its ID, which is "modalContent". So we'll say WebElement modal = driver.findElement By.id, (keyboard keys clicking) and that ID is "modalContent". Then we'll say if the modal is displayed, and we can print a message. Let's say "modal is displayed". (keyboard keys clicking) Then we interact with the modal's elements just as we would with any other elements. The ID of the modal's text field is "modal-input". We can find that element and then send keys to type into it. So let's say: driver.findElement(By.id) "modal-input", and then we can call sendKeys(). And we can type anything in here, how about "hey modal". Great, and then to close the modal, we'll find the modal's close icon, which has an ID of…

Contents