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.

17 comments:

  1. Thanks For Explaining In Detail for us.Thanks Very Remarkable!
    Selenium Online Training In Bangalore

    ReplyDelete
  2. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Data Science with Python training in chenni
    Data Science training in chennai
    Data science training in velachery
    Data science training in tambaram
    Data Science training in OMR
    Data Science training in anna nagar
    Data Science training in chennai
    Data science training in Bangalore

    ReplyDelete
  3. Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
    java training in chennai | java training in bangalore

    java online training | java training in pune

    java training in chennai | java training in bangalore

    ReplyDelete
  4. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
    python training in tambaram
    python training in annanagar
    python training in OMR
    python training in chennai

    ReplyDelete
  5. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    Blueprism training in Chennai

    Blueprism training in Bangalore

    Blueprism training in Pune

    ReplyDelete
  6. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.

    angularjs-Training in chennai

    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete
  7. Were a gaggle of volunteers as well as starting off a brand new gumption within a community. Your blog furnished us precious details to be effective on. You've got completed any amazing work!

    python training in velachery | python training institute in chennai

    ReplyDelete
  8. Hi,
    Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take data science training in pune. Because data science course in pune is one of the best that one can do while choosing the course.

    ReplyDelete
  9. I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article


    Java training in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Online Training

    ReplyDelete