Handle Alert Pop up Boxes - naveens33/selenium_python GitHub Wiki

Types of Alert/Pop up boxes

  1. Windows-based alert pop-up
  2. Web-based alert pop-up

Windows-based alert pop-up

Windows-based alert pop-up is cannot be automated with Selenium. We can automate those alert boxes with Thrid part tools like AutoIt and Sikuli.

Examples of Windows-based alert pop-up are,

  • Open window
  • Save window

Web-based alert pop-up

Web-based alert pop-up is triggered by the web page. Below are the types of Web-based alert pop-up.

  • Simple Alert
  • Confirmation Alert
  • Prompt Alert

How to automate Web-based alert pop-up.

Switch the focus from the parent page to the Alert box

Whenever an Alert/pop-up box appears on the web page. The control remains with the parent web page only. So the first you need to switch the focus from the parent page to the Alert/pop-up box. You can switch the focus of the parent page to Alert box through the following code snippet.

alert = driver.switch_to.alert

Once the control moved to the alert box. You can use the following methods to handle it

Method Description
alert.accept() To click the Ok button
alert.dismiss() To click the Cancel button
alert.text To get the alert message
alert.send_keys() To send some text to the alert box