How do I test modal dialogs with Selenium?

只谈情不闲聊 提交于 2019-11-30 19:13:19

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.

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.

Emy Jamalian

This is how I handle pop up alert in Selenium IDE

right click on the element (in this case your pop up window) there are some command you can choose. There's also a show all available commands whiche might be a help. You should use AssertElementPreset and I guess the best locator in this case is CSS. So you can choose AssertElementPresent.

Or

you can use two command on Selenium IDE

selectWindow | null
verifyElementPresent | css=div.content

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!