Handling pop ups/alert/confirmations/prompts in Selenium

How does one handle the following in Selenium in case of JavaScript and YUI:
  1. Pop Ups
  2. Alerts
  3. Confirmations
  4. Prompts

I have googled a lot on this topic, but not found any help on this as such. Any help/ guidance for the above will be much appreciated.

Tags: JS, Javascript, Selenium, YUI, alerts, confirmations, popups, prompts

Views: 11701

Reply to This

Replies to This Discussion

Selenium does not handle certain set of popups. If you are using Selenium then you need to look for integrating another open source tool e.g. Autoit, to start handling those popups with your selenium scripts.
You can use Sahi (http://sahi.co.in) to test these.
Can I have a reply on 'How to do data driven Testing in Sahi'?

An easy way to do data driven testing in Sahi is to use PushToTest TestMaker. See http://www.pushtotest.com/test-rich-internet-application-using-test...


Javascript's pop-up dialogs should be specified somewhere in the document's DOM model. In some JS frameworks dialogs create events on it's action, e.g. Jquery UI raise different events on different kinds of actions. You can learn more about this on http://jqueryui.com/demos/dialog/ in tab Events.
We can use Selenium RC to handle the pop-up windows. There are different methods available to deal with different types of pop-up windows. Following are some methods that I have used to handle pop-up windows/JavaScript alerts using Selenium RC java client.


These method calls should be executed before the event that generates the Pop-up windows /JavaScript alerts. e.g. if clicking a Delete button pop-up a java script alert with OK and Cancel button then functions call would be.


This would instruct selenium to click OK on the pop-up window that appears as a result of clicking the delete button.

Sample Soure Code:

//Click 'Ok' button on pop-up window
//Click 'Delete' button
assertTrue(selenium.getConfirmation().matches("^Conferm cancel [\\s\\S]$"));

Can Selenium handle IE Security Alert, e.g. like this?
thanks for the RC comands.....
can you plz elaborate a bit on the below commands....
1. selenium.click("//img[@alt='Delete']");
2.assertTrue(selenium.getConfirmation().matches("^Conferm cancel [\\s\\S]$"));
I mean are they the Xpath of the elemnt.....? which properties are they.......
How to click on the Popup which has only "OK" button on it.....
UI Developer here... we have a standard YUI dialog with (submit) and (cancel) buttons, but had trouble testing because of course YUI gives them dynamic IDs and you can't predict the ID. What I did in the .js:

Initialize the dialog...

var myNewDialog = YAHOO.dialog.initialize ("container", "width");

Then before you go to .show() the dialog, do this:

var submitButton = YAHOO.dialog.myNewDialog.getButtons()[0];
submitButton.set('id', "submit-button");
var cancelButton = YAHOO.dialog.myNewDialog.getButtons()[1];
cancelButton.set('id', "cancel-button");
This doesn't end up changing the button elements in your HTML at all, but does assign the ID to the grandparent Span element in the XPath. So now you have your static paths:

Thanks Andrew, I will ask our developers to try this option surely.


© 2014   Created by Test Republic.

Badges  |  Report an Issue  |  Terms of Service