课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

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…

内容