Alerts¶
Using the methods below you will be able to handle the three types of native popup dialogs from JavaScript:
- Alerts
- Confirmations
- Prompts
Retrieving a Dialog¶
You can retrieve a Dialog to interact with it and fetch information about it such as the message content.
import org.openqa.selenium.Alert;
// Retrieve the dialog. If no dialog is found, the dialog will receive None.
Alert dialog = getJsDialog();
// Get the message content of the dialog.
System.out.println(dialog.getText());
// Close the dialog.
dialog.dismiss();
// Accept the dialog.
dialog.accept();
// Reply to the dialog.
dialog.sendKeys("Hello Dialog!");
Handling Dialogs¶
As we have seen above, you can retrieve a Dialog to interact with it and fetch information about it such as the message content.
We also offer a shortcut to handle the dialogs: