Handling alerts   

Apart from switching between windows and frames, you may have to handle various modal dialogs in a web application. For this, WebDriver provides an API to handle alert dialogs. The API for that is as follows:

Alert alert()

The preceding method will switch to the currently active modal dialog on the web page. This returns an Alert instance, where appropriate actions can be taken on that dialog. If there is no dialog currently present, and you invoke this API, it throws back a NoAlertPresentException.

The Alert interface contains a number of APIs to execute different actions. The following list discusses them, one after the other: