Skip to content
CodeKruPro

Read a modal without treating it as an alert

Automation taskMediumPython onlyAsked in: Accenture, Capgemini, Infosys, TCS, Wipro

A classic confusion: "The pop-up is not an alert, and switching to the alert fails. Why?" A modal (a pop-up window) built with HTML is part of the page, while an alert is drawn by the browser. Find the modal with normal locators and wait for it to be visible.

Read a Modal Without Treating It as an Alert

Read a Modal Without Treating It as an Alert

The custom modal is HTML in the page. It is not a browser alert. Do not use switch_to.alert. The buttons have no ids.

Task:

  1. Click Open Modal
  2. Wait until #customModal .modal-body is visible
  3. Print its text
  4. Click Close inside the modal

Print the lines below exactly.

Expected output:

Modal: This is a custom modal popup. You can test handling it in automation.