I understand that a modal dialog is an alert or child window that, according to Wikipedia, “requires users to interact with it before they can return to operating the parent application”.
All instances of modal dialogs that I found in HTML pages are simple <div> elements like the JQuery dialogs. Some of them really block user interaction from the main page with an overlay, but some are not even ‘modal’, because user’s can easily interact with the main page while the dialog is present.
I’m asking this because I’m getting an UnhandledAlertException: “Modal dialog present” by one of my Selenium tests. And I wonder: how does Selenium know that a modal dialog is present? Seeing many <div> elements on the HTML page, what’s the special attribute that makes one of them a ‘dialog’ and all other not? And what’s the second attribute that causes a dialog to become ‘modal’?
A pseudo-modal dialog is in most cases two divs, one covering the whole window being transparent or tinted, while another div on top of that represents the actual dialog (or a combination where a single div do both).
To detect this you need to iterate through the dom to find the div with the biggest size (close to the window size), located at position 0,0 and with position attribute set to absolute or fixed, as well it’s z-index.
There is however no guarantee that this works for every case (and there exist various implementations) which means a detection routine only can do a good guess.