A pop-up is a browser window that opens randomly on surfing the Internet through the web browser. Web applications generate three different types of pop-ups, namely:
JavaScript alert (pop-ups) (for example, advertisements)
Browser pop-up (for example, a confirmation dialog box, an authentication prompt, and so on)
Native OS pop-ups (for example, Windows pop-ups such as upload/download notfications)
JavaScript pop-ups are generally in the form of alerts and advertisements, especially for marketing purposes. Selenium WebDriver provides an API to handle the JavaScript pop-ups. The following is an example of an alert:
Alert alert = driver.switchTo().alert();
Some of the helpful snippets using JavaScript alert functions are as follows: