ISTQB Certified Software Test Engineer

Friday, October 25, 2013

Seleniumr-Handling Unexpected Popups

Some times When we are doing automation using Selenium , sometimes unexpected popups/alert message will appear on the screen.An automation engineer doesn't have a code to handle this when it is unexpected (since it is inconsistent),this leads to script failure.
In Selenium there is way to handle these unexpected alert/popup messages in the following way.
When ever we have unexpected popup/alert appears in the application,it throws an unhandled alert exception and script will fail. So We have to handle this unhandled alert exception in our test method and then we need to switch to the original content.

Example:
@Test
public void googleTest(){
try{
driver.get("http://google.com");
driver.findElementById("q").sendkeys("selenium");
}
catch(UnHandledAlertException e){
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
}}


The above test method explains about handling unexpected popups.
When ever we have an UnHandlerdAlertException,catch that excption,switch to alert and accept that alert.
Then Switch to Default Content means the original Content.

1 comment:



  1. Well did here, a set of useful interview questions which looks really helpful a lot to learn about the subject and also during interviews. But now a days Manual testing is not so enough to get placed in MNC companies, hence here I like to share some the most trending area in software testing field, which is Selenium -- A Top trending automation testing tool. Learn more about Selenium here ==> Best Selenium Training Institute in Chennai
    FREE PDF download the course content ==>
    Selenium Training in Velachery

    ReplyDelete