课程: Test Automation with Selenium WebDriver for Java
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Alerts
- [Instructor] Unlike modals that are embedded in the DOM, alerts are popup messages that are invoked by JavaScript. Since alerts are not part of the DOM, we can't access them using element locators. Fortunately, Selenium WebDriver offers methods specifically designed to interact with alerts. Let's write a script that gets the text from this alert. Our code has already clicked the link that triggers the alert, and to access this alert, we can say driver.switchTo.alert. And this returns an alert object. So let's assign that, Alert alert equals. Now we can get the message that appears within the alert by saying, String message equals alert.getText. We cannot continue doing anything with WebDriver until we handle this alert. So let's click the OK button. Now remember the alert is not in the DOM, so we can't use the click method here, but the alert class provides the accept method, which will click OK. So we say alert.accept. Now let's look at a confirmation alert, which requires the user…
内容
-
-
-
-
-
-
-
-
(已锁定)
Browser information1 分钟 17 秒
-
(已锁定)
Navigation1 分钟 44 秒
-
(已锁定)
Tabs3 分钟 24 秒
-
(已锁定)
Modals2 分钟 21 秒
-
(已锁定)
Alerts4 分钟 8 秒
-
(已锁定)
iFrames2 分钟 3 秒
-
(已锁定)
Cookies3 分钟 6 秒
-
(已锁定)
Taking screenshots7 分钟 35 秒
-
(已锁定)
Code Challenge: Accept alert in new tab37 秒
-
(已锁定)
Solution: Accept alert in new tab39 秒
-
(已锁定)
-
-
-