Handle Alerts, Prompt and Confirm Box
Handle Alerts, Prompt and Confirm Box
Handle Alerts, Prompt and Confirm Box
ON
Handle Alert, Prompt and Confirm Box
Submitted by
Sana
Case Study: Handle Alert, Prompt and Confirm Box
Problem Statement:
1) Identify and Handle Popups
2) Entering user data in an alert, Accept or Cancel the
alerts
Handle Alert, Prompt and confirm Box
Table of Contents
1.Project Objective
2.Assumptions
3.Handling Alerts and Popups -Step by step approach
3.1 Selenium IDE Set up.
3.2 Adding Selenium jar files.
3.3 Configuring the driver path.
3.4 Handling the multiple Browsers.
3.5 Handling the Alerts, Popups and Confirm boxes.
3.6 Executing the appropriate hands-on code.
3.7 Obtaining the corresponding results.
4. Conclusion
3
Handle Alert, Prompt and confirm Box
Project Objective:
Suggested site: http://demo.automationtesting.in/Alerts.html
Detailed Description:
4
Handle Alert, Prompt and confirm Box
5
Handle Alert, Prompt and confirm Box
Simple alert: These alerts are just informational alerts and have
an OK button on them. Users can click on the OK button after reading the
message displayed on the alert box
Prompt Alert: In Prompt alerts, some input requirement is there from the
user in the form of text needs to enter in the alert box. A prompt alert box is
displayed like below, where the user can enter his/her username and press
the OK button or Cancel the alert box without entering any details .
Confirmation Alert: These alerts get some confirmation from the user in
the form of accepting or dismissing the message box. They are different
from prompt alerts in a way that the user cannot enter anything as there is no
text-box available. Users can only read the message and provide the inputs by
pressing the OK/Cancel button.
driver.switchTo( ).alert( );
Once we switch the control from the main browser window to the alert window,
we can use the methods provided by Alert Interface to perform various
required actions. For example, accepting the alert, dismissing the alert, getting the
text from the alert window, writing some text on the alert window, and so on.
6
Handle Alert, Prompt and confirm Box
Void accept(): This method clicks on the 'OK' button of the alert box.
Void dismiss(): We use this method when the 'Cancel' button clicks in the alert
box.
String getText(): This method captures the message from the alert box.
driver.switchTo().alert().getText();
Void sendKeys(String stringToSend): This method sends data to the alert box.
driver.switchTo().alert().sendKeys("Text");
7
Handle Alert, Prompt and confirm Box
8
Handle Alert, Prompt and confirm Box
Creating testng.xml
9
Handle Alert, Prompt and confirm Box
10
Handle Alert, Prompt and confirm Box
11
Handle Alert, Prompt and confirm Box
12
Handle Alert, Prompt and confirm Box
13
Handle Alert, Prompt and confirm Box
14
Handle Alert, Prompt and confirm Box
15
Handle Alert, Prompt and confirm Box
16
Handle Alert, Prompt and confirm Box
17
Handle Alert, Prompt and confirm Box
18
Handle Alert, Prompt and confirm Box
19
Handle Alert, Prompt and confirm Box
Console Output:
20
Handle Alert, Prompt and confirm Box
Conclusion:
In this mini project, Handling Alerts, Prompts and Confirm Boxes, I have
implemented the project using Selenium IDE for automation testing.
Through this project I have implemented the Alert Class and handled
multiple browsers through which the web elements are navigated.
Exceptions are also handled during run time of the execution.
21