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