Pages

Search This Blog

Thursday, August 19, 2010

How to handle the input promt dialog in selenium

There are some scenarios where we need to input when our web application need external input data by opening input prompt dialog box. To handle these dialog boxes in automation is tricky task. We can handle these situation with below codes.
Html file is at the bottom

selenium.open("Input_prompt_TestCase.html");

Verify there is no input dilog present while opening this file


assertTrue(!selenium.isPromptPresent());

When then Input prompts select NO first time by the command answerOnNextPrompt|no|

selenium.answerOnNextPrompt("no");

Now click to open the input dialog by clicking the link "Click here to open input dialog"

selenium.click("promptdialog");

Now verify prompt presents or not with the command verifyPromptPresent||
assertTrue(selenium.isPromptPresent());
If it takes time to open the prompt then we can wait till 1 minute with the below code.

boolean Bool = false;
for (int second = 0; second < 60; second++) { 
try { 
if ((selenium.isPromptPresent())) {
Bool = true;
break; 
}
}
catch (Exception ignore) {
}
pause(1000);
}
assertTrue(Bool);


Now after 1 minute verify the prompt presents or not with the command assertPromptPresent||


assertTrue(selenium.isPromptPresent());

If it verifies prompt is there then verify the text what is on prompt with the command
verifyPrompt|Type 'automationtricks' and click OK|


verifyEquals("Type 'automationtricks' and click OK", selenium.getPrompt());

You can also verify the title of input prompt with the command verifyTitle|Test Prompt|


verifyEquals("*Testcases for input Prompt", selenium.getTitle());

Now you just enter automationtricks in input promt with this command
answerOnNextPrompt|automationtricks|


selenium.answerOnNextPrompt("automationtricks");

and then click on ok with command clickAndWait|promptdialog|


selenium.click("promptdialog");

Now you can see the result based on your input


selenium.waitForPageToLoad("5000");
verifyTrue(selenium.isTextPresent("You have entered automationtricks!"));



For Selenium IDE user : How to handle prompt in selenium IDE


<tr>
<td>open</td>
<td>Input_prompt_TestCase.html</td>
<td></td>
</tr>
<tr>
<td>answerOnNextPrompt</td>
<td>automationtricks</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>promptdialog</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>You have entered automationtricks!</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>Input_prompt_TestCase.html</td>
<td></td>
</tr>
<tr>
<td>answerOnNextPrompt</td>
<td>niraj</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>promptdialog</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>You have not entered automationtricks!</td>
<td></td>
</tr>


For the above code find Html file below


<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html">
<script type="text/javascript">
function opendialog() {
if (prompt("Type 'automationtricks' and click OK") == 'automationtricks') {
document.write("You have entered automationtricks!");
}
else{
document.write("You have not entered automationtricks!");
}
}
</script>
<title>Testcases for input Prompt</title>
</head>
<body>
<img style="width: 644px; height: 41px;" alt="banner" src="banner.gif"><br>
<a id="promptdialog" href="javascript:opendialog();">Click here to open input dialog</a>
</body>
</html>


39 comments:

  1. Hi All I forgot to add HTML file to test above code.
    You can use below html to run above script.

    HTML file
    =================

    <html>
    <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html">
    <script type="text/javascript">
    function opendialog() {
    if (prompt("Type 'automationtricks' and click OK") == 'automationtricks') {
    document.write("You have entered automationtricks!");
    }
    else{
    document.write("You have not entered automationtricks!");
    }
    }
    </script>
    <title>Testcases for input Prompt</title>
    </head>
    <body>
    <img style="width: 644px; height: 41px;" alt="banner" src="banner.gif"><br>
    <a id="promptdialog" href="javascript:opendialog();">Click here to open input dialog</a>
    </body>
    </html>

    ReplyDelete
  2. Hi Mr. Nirja

    Accidentally, I happened to see this post and it was useful for me to know the usage of the answerOnNextPrompt and nice explanation.

    you can post some other examples on various Selenium commands which will be useful to beginners like me.

    ReplyDelete
  3. Thank you so much for this post.

    ReplyDelete
  4. Hi Niraj

    Thanks, this is a great article you posted. It really helped me.Great work keep it up.

    ReplyDelete
  5. Malaysia & Singapore & brunei ultimate online blogshop for wholesale & quantity korean add-ons, accessories, earstuds, pendant, rings, hair,
    bracelet & bracelet add-ons. Offer 35 % wholesale rebate. Ship Worldwide
    my web page :: Onesie

    ReplyDelete
  6. Malaysia & Singapore & brunei ultimate on-line blogshop for wholesale & quantity korean add-ons, accessories, earstuds, choker, rings, bangle, hair & bracelet
    add-ons. Deal 35 % wholesale price cut. Ship Worldwide
    Here is my webpage Bondi tradesman

    ReplyDelete
  7. Malaysia & Singapore & brunei greatest on the internet blogshop
    for wholesale & supply korean accessories, earrings, earstuds, necklace, rings, hair, bangle & trinket add-ons.
    Promotion 35 % wholesale markdown. Ship Worldwide
    My website: music marketing

    ReplyDelete
  8. Great post! We will be linking to this great content on our site.
    Keep up the good writing.
    Also visit my web blog diet tips

    ReplyDelete
  9. I loved as much as you'll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get bought an edginess over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase.
    Feel free to surf my blog - Trick Photography & Special Effects

    ReplyDelete
  10. I started learning SeleniumIDE commands. But i found this post has the nice explination of commands so far. Thank u sooooooo much. Very nice explination. Great job.

    ReplyDelete
  11. This is really interesting, You are a very skilled blogger.
    I've joined your rss feed and look forward to seeking more of your excellent post. Also, I've shared your website in my social networks!
    Also see my web site > click the up coming site

    ReplyDelete
  12. Hi there, I log on to your blogs on a regular basis.
    Your writing style is witty, keep doing what you're doing!
    Also see my site > Go Here

    ReplyDelete
  13. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community
    in the same niche. Your blog provided us useful information to work on.
    You have done a wonderful job!
    Feel free to visit my site :: diet doctor Miami

    ReplyDelete
  14. Amazing! This blog looks exactly like my old one!
    It's on a entirely different topic but it has pretty much the same page layout and design. Wonderful choice of colors!
    Also see my web page: Miami diet physician

    ReplyDelete
  15. Amazing blog! Is your theme custom made or did you download
    it from somewhere? A design like yours with a few simple tweeks would really make my blog shine.
    Please let me know where you got your theme. With thanks
    Feel free to surf my web page :: sailing charter ecommerce specialist

    ReplyDelete
  16. Hi! I realize this is sort of off-topic however I had to ask.
    Does running a well-established website like yours take a large amount of work?
    I am completely new to running a blog however I do write in
    my diary on a daily basis. I'd like to start a blog so I will be able to share my experience and views online. Please let me know if you have any suggestions or tips for new aspiring bloggers. Appreciate it!
    Have a look at my web page ... wedding insurance comparisons

    ReplyDelete
  17. I feel that is one of the such a lot significant information for me.
    And i'm satisfied studying your article. But should observation on few normal things, The site taste is great, the articles is really great : D. Good process, cheers
    Here is my web-site Ways to Become a Millionaire

    ReplyDelete
  18. Wow! At last I got a blog from where I know how to in fact obtain helpful information regarding my study and knowledge.


    Feel free to visit my page :: get healthy without cigarettes

    ReplyDelete
  19. Fantastic site. Lots of useful info here. I'm sending it to several buddies ans also sharing in delicious. And naturally, thank you in your effort!

    My page: cheap gw2 gold

    ReplyDelete
  20. You've made some good points there. I checked on the net for more info about the issue and found most individuals will go along with your views on this web site.

    Stop by my webpage: guild wars 2 gold

    ReplyDelete
  21. We are a group of volunteers and opening a new scheme in our community.

    Your website provided us with useful information to work on.

    You have done a formidable task and our whole neighborhood will likely be grateful to you.


    Also visit my web site: canadian online casino

    ReplyDelete
  22. This cοst is the cоst effectivenеss.
    Βеing an AϹN Mom myself іn Ѕpencer Hunn's downline I can say anything I want business on here. Think of Google Docs, and archived for retrieval at a later point in time development will have to pass on my two cents worth of ideas and new concepts.

    Review my website - www.georgesvanier.com

    ReplyDelete
  23. As Pinterest's internal analytics capabilities evolve those center business decision makers will become known, and when they do, concentrating on their core skills.

    Here is my homepage - how to improve seo

    ReplyDelete
  24. I think this is among the most important info for me. And i am glad reading your article.
    But wanna remark on few general things, The web site style is wonderful, the articles is really great : D.
    Good job, cheers

    Take a look at my web blog - http://www.wildpartygirls.org/

    ReplyDelete
  25. I know this if off topic but I'm looking into starting my own blog and was wondering what all is required to get set up? I'm assuming having a blog like yours would cost a
    pretty penny? I'm not very web savvy so I'm not 100% positive.
    Any tips or advice would be greatly appreciated. Thank you

    Also visit my web-site - teens outdoor orgy

    ReplyDelete
  26. Whats up this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to
    manually code with HTML. I'm starting a blog soon but have no coding expertise so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

    Look at my page http://sexygirlchat.net

    ReplyDelete
  27. You can certainly see your expertise within the
    article you write. The sector hopes for more passionate writers like you who aren't afraid to say how they believe. At all times go after your heart.

    my webpage cuteteenporn.net

    ReplyDelete
  28. Hello friends, its impressive piece of writing concerning cultureand fully explained, keep it up all the
    time.

    Check out my web page; onhiddencam.info

    ReplyDelete
  29. Hey there! I know this is sort of off-topic but I needed
    to ask. Does running a well-established blog such as yours
    require a large amount of work? I'm brand new to running a blog but I do write in my diary every day. I'd
    like to start a blog so I will be able to share my experience and views
    online. Please let me know if you have any kind of suggestions or
    tips for new aspiring blog owners. Thankyou!

    Also visit my site :: cuteteenporn.net

    ReplyDelete
  30. Excellent web site you have here.. It's difficult to find quality writing like yours nowadays. I honestly appreciate individuals like you! Take care!!

    Stop by my web blog: jnmassage.info

    ReplyDelete
  31. Hello, its fastidious piece of writing on the topic of media print, we all be familiar with media is a
    impressive source of data.

    my webpage: get free porn movies

    ReplyDelete
  32. Hello, just wanted to mention, I loved this post.
    It was practical. Keep on posting!

    my site; www.cfnmfever.net

    ReplyDelete
  33. Today, I went to the beachfront with my kids. I found a sea shell and gave it to my 4 year old
    daughter and said "You can hear the ocean if you put this to your ear." She put
    the shell to her ear and screamed. There was a hermit crab
    inside and it pinched her ear. She never wants to go back!
    LoL I know this is totally off topic but I had to tell someone!


    Also visit my site http://hotgirlsexcam.com/videos/Natalie-webcam-VI-176

    ReplyDelete
  34. Hey there fantastic website! Does running a blog similar to this require a lot of work?

    I have virtually no knowledge of coding but I was hoping to start my own blog soon.
    Anyways, if you have any suggestions or techniques for new blog owners please
    share. I know this is off subject but I just wanted to ask.
    Kudos!

    Check out my homepage ... tabitha stevens porn star ()

    ReplyDelete
  35. Thanks for providing good article on "How to handle the input prompt dialog in selenium". http://reditblog.blogspot.in/

    ReplyDelete
  36. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  37. It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

    ReplyDelete
  38. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete