How do I test modal dialogs with Selenium?

17,977

Solution 1

From the Selenium FAQ, Selenium apparently works with some types of dialogs but not others:

I can't interact with a popup dialog. My test stops in its tracks!

You can, but only if the dialog is an alert or confirmation dialog. Other special dialogs can't be dismissed by javascript, and thus currently cannot be interacted with. These include the "Save File", "Remember this Password" (Firefox), and modal (IE) dialogs. When they appear, Selenium can only wring its hands in despair.

To solve this issue, you may use a workaround (if one exists); otherwise you may have to exclude the test from your automated corpus. For the "Save File" dialog in Firefox, a custom template may be specified when running via the RC that will always cause the file to be downloaded to a specified location, without querying the user (see http://forums.openqa.org/thread.jspa?messageID=31350). The "Remember this Password" dialog should not appear again after you've chosen to remember it. Currently there is not much that can be done about IE modal dialogs.

I seem to remember someone working around this with an AutoHotKey script that dismissed the dialog.

Solution 2

I have been using Selenium IDE to test jQuery modals for quite sometime now, I never faced any problem. Here are the things I do to ensure that the test executes properly on playback:

  • execute the script at the slowest possible speed
  • when the modal opens, I use the waitForElementPresent command to verify the presence of at least one of the constituent elements on the page; argument being, if one element loads properly, it is safe to assume that all the elements and hence the modal window loaded up properly.

Hope this helps. If you want further help, you can share the code with me alongwith the error in execution that IDE throws out to you.

Solution 3

Modal window hacked:) http://seleniumdeal.blogspot.com/2009/01/handling-modal-window-with-selenium.html

Share:
17,977
Michael Haren
Author by

Michael Haren

These days I'm a .net/sql software guy I have plenty of experience on the LAMP stack, too Currently toying with RoR, ObjC. and stumbling my way through LINQ to Entities Currently loving ASP.NET MVC and jQuery More about be on my CV or personal blog [email protected] Random silliness on Twitter This is a personal account and not affiliated with my employer. #SOreadytohelp

Updated on July 17, 2022

Comments

  • Michael Haren
    Michael Haren almost 2 years

    I'm getting started with Selenium IDE and trying to test a webapp that's full of modal dialogs (window.showModalDialog).

    Recording the test seems to work (except there's nothing in the log when the dialog pops up) but they don't play back properly. The script actually opens the window (triggered by a button click), but then just waits indefinitely.

    Any suggestions?

  • Michael Haren
    Michael Haren about 15 years
    The problem is that these aren't small dialogs--they are rich interfaces that need tested. I'll try something else, I guess. Thanks!