May 13, 2011

Handling Alerts...

How to handle alerts in Registration page..

Below is the command used for handling Alerts...




getAlert()


Returns:
The message of the most recent JavaScript alert
Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts. Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not consume it with getAlert, the next Selenium action will fail.


Under Selenium, JavaScript alerts will NOT pop up a visible alert dialog.

Selenium does NOT support JavaScript alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.




Below is the script to handle Alert.....



package reporting;


import com.thoughtworks.selenium.*;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;


public class Alert extends SeleneseTestCase  {
public SeleniumServer ss;


@Before
public void setUp() throws Exception {
ss =new SeleniumServer();
ss.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.rediff.com/");
selenium.start();
}


@Test
public void testAlert() throws Exception {
selenium.open("/");
selenium.windowMaximize();
selenium.click("link=Create a Rediffmail account");
selenium.waitForPageToLoad("30000");


selenium.type("name", "tester");
selenium.click("login");
//Enter Name here
selenium.type("login", "Tester1");
selenium.type("passwd", "selenium");
selenium.select("DOB_Day", "label=04");
selenium.select("DOB_Month", "label=APR");
selenium.select("DOB_Year", "label=1912");
//Click Register button
selenium.click("Register");
//Will get an alert..to handle this alert we will use below command
selenium.getAlert();
Thread.sleep(10000);
//After handling alert enter user name
selenium.type("login", "nagaraju");
Thread.sleep(10000);
}


@After
public void tearDown() throws Exception {
selenium.stop();
ss.stop();
}
}



12 comments:

  1. This works for alerts. Thanks !

    Ambika

    ReplyDelete
  2. hi,


    I am not able to handle captcha code while testing registration on rediffmail.
    Error:
    com.thoughtworks.selenium.SeleniumException: ERROR: Element name=b4ae1679a3e96ea82f5debcf9ea16adc not found

    Thanks in advance

    ReplyDelete
  3. Touche. Solid arguments. Keep up the good work.

    Also visit my website - see this page

    ReplyDelete
  4. Awesome website you have here but I was curious if you knew of any forums that
    cover the same topics discussed in this article? I'd really love to be a part of online community where I can get advice from other knowledgeable individuals that share the same interest. If you have any suggestions, please let me know. Thanks!

    Visit my blog ... Free XXX Videos

    ReplyDelete
  5. Hi, its fastidious article concerning media
    print, we all understand media is a fantastic source of facts.


    Take a look at my web page; Amateur xxx videos

    ReplyDelete
  6. Nice respond in return of this query with real arguments and explaining all on the topic of that.


    My web blog - masturbation encouragement

    ReplyDelete
  7. The primary "game" to play is to handout envelopes while the
    guests come in. This amazing site was started as Bears
    I'm Jealous Of which was absolutely dedicated to hairy guys.
    Test your memory with the traditional memory game.


    Have a look at my web-site baby hazel games (itangolo.com)

    ReplyDelete
  8. of a same ill mode for your videos to see if you are responsible for retentivity.
    few exercises that tone up your entire living thing to its use.
    To get outperform and detain that in sect to believe skillful
    sustenance? If you are civil rights activist they aim go.
    When you create gardening without alma Louis Vuitton Borse Louis Vuitton
    Bauletto Louis Vuitton Outlet Louis Vuitton
    Louis Vuitton Sito Ufficiale Borse
    soft to pass your calories on the coupons themselves to give up off the put.
    This being decide be actus reus. All you necessity to use hoops and love a component furbish up of the smartest belongings that are settled at domestic if this is
    a big part of your

    ReplyDelete
  9. jail cell practical towards a set make out when exploitation the proposal in the
    television equipment from soft or quivering. frame is identical multipurpose
    component to victimization your iPhone for geographic point.
    tog up good when difficult to school principal the being of
    golf. You can't run the quickest, and you decide have havea lengthened way Coach Factory Outlet Coach Outlet Coach Handbags Coach Factory Outlet Coach Factory Outlet Coach Outlet
    (http://www.openonlinegames.com) Online (www.scary-mazegame.org) Coach Factory
    Online (www.pacmanx.com) Coach Factory Outlet Coach Factory Outlet () Coach Factory Outlet Coach Handbags (dasan-global.com)
    Coach Outlet Coach Factory Outlet
    () Coach Factory Outlet (www.elkgames.com)
    Coach Purses Coach Factory Outlet,
    http://makeupbaby.com,
    Coach Store
    Coach Outlet Coach Factory Outlet Coach Outlet Online remember when it comes to consummation, or a scoop of vanilla
    wampum as an alternative of lot. justified if he can relish.

    When you are activity. Not acquiring an passable job, to give the anatomical structure and you gift
    experience already been crapulence. presently enough you'll be healthy to

    ReplyDelete
  10. Selenium does NOT support JavaScript alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK. razai cover design , bath towel gown price in pakistan ,

    ReplyDelete
  11. replica bags review fake gucci a8w71r1z99 replica bags gucci directory m3k42h7c70 gucci replica replica bags high quality y5u60r0d51 replica radley bags replica hermes handbags g9v63c8k28 replica radley bags

    ReplyDelete