Test Republic

Community of Software Testing Professionals

Indira Pai

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: alerts, confirmations, javascript, js, popups, prompts, selenium, yui

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.

Reply to This

You can use Sahi (http://sahi.co.in) to test these.

Reply to This

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.

Reply to This

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.

selenium.chooseCancelOnNextConfirmation();
selenium.chooseOkOnNextConfirmation();

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.

selenium.chooseOkOnNextConfirmation();
selenium.click("DeleteButton");

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
selenium.chooseOkOnNextConfirmation();
//Click 'Delete' button
selenium.click("//img[@alt='Delete']");
assertTrue(selenium.getConfirmation().matches("^Conferm cancel [\\s\\S]$"));
selenium.waitForPageToLoad("90000000");
selenium.click("sm-event.ADClient-ADSearchBase.Back");

selenium.waitForPageToLoad("90000000

Reply to This

Can Selenium handle IE Security Alert, e.g. like this?

Reply to This

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");

Reply to This

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:

//span[@id='submit-button']/span/button
//span[@id='cancel-button']/span/button

Reply to This

RSS

Test Republic Elsewhere

 /></a></p> <p style=

Members

  • Vijayalaxmi
  • Sreethin
  • P.K.Ramya
  • Brian Osman
  • s kumar
  • Shreya
  • APARNA
  • Sanjeev Kumar Singh
  • BIDISHA BAGCHI
  • Ipsita ratha
  • Sapna Nair
  • Gaurav  Deore
  • anupam
  • Bhavani
  • Shiva Kumar

© 2010   Created by EDISTA.

Badges  |  Report an Issue  |  Terms of Service