As per my understanding Pop-Ups are classified into three types.

1.) JavaScript alerts:
By default Selenium suppress the alerts during test execution, so not visible on the browser. If the alerts are not handled properly Selenium through following exception "com.thoughtworks.selenium.SeleniumException: ERROR: There was an unexpected Confirmation! [Do you want to Continue?]". This alert is further classified into "ok" , "ok and cancel" alert. This alert can be handled in the following way.

assertEquals("Saved Sucessfully!", s.getAlert()); // After click
s.chooseOkOnNextConfirmation(); // Before Click
s.chooseCancelOnNextConfirmation(); // Before Click
s.getConfirmation(); // After click

For "ok and cancel" alert, you need to consume the alert with "s.getConfirmation();" other wise it will display the exception saying "ERROR: There was an unexpected Confirmation!". Basically you should be using two statements: (ok/cancel)conformation before the click and consume after the click.

If you insert an alert statement when there is no alert on the web page, selenium will display following exception - com.thoughtworks.selenium.SeleniumException: ERROR: There were no alerts

2.) HTML Pop-Ups using JQuery or other techniques :
Here popup is constructed using div and is visible on the screen. This can be handled in the following way

s.click("popup_ok")
s.click("popup_cancel")

3.) Windows Pop-Ups :
These are windows based popup and is visible on the screen. Selenium is not capable to handle this kind of pop-up, need to use AutoItv3. To handle this pop-up record the script in AutoItv3, convert into exe format and then call from Java program.

Runtime.getRuntime().exec("C:\\OKbtn.exe ");

WinWaitActive("#32770", "Message from webpage",10)

WinFlash("Message from webpage","", 4, 500) ; Just to Flash the window

ControlClick("Message from webpage", "","[CLASS:Button; INSTANCE:1]");


second Method

you can always use Java Robot library and imitate pressing e.g. Enter key

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

or define firefox profile to not display popups.


Thanks

Vivek

Get more Testing documents : http://testingking.weebly.com/poll-of-the-day.html

Share