0% found this document useful (0 votes)
24 views30 pages

Lab 6 - Handling Alerts and Pop Ups

Pop ups

Uploaded by

jellyfish0145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views30 pages

Lab 6 - Handling Alerts and Pop Ups

Pop ups

Uploaded by

jellyfish0145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Software Quality Assurance

1 Lab 6
Handling Alerts and Popups
2 Agenda

 What is Alert in Selenium?


 Types of Alerts in Selenium.
 How to handle Alert in Selenium WebDriver?
 How to handle Pop-up window using Selenium Webdriver?
 How to Handle Multiple Windows in Selenium?
 How to copy xPath from Chrome
3 What is Alert in Selenium?

 An Alert in Selenium is a small message box which appears on screen to


give the user some information or notification. It notifies the user with
some specific information or error, asks for permission to perform
certain tasks and it also provides warning messages as well.
 we will learn how to handle popup in Selenium and different types of
alerts found in web application testing, We will also see how to handle
Alert in Selenium WebDriver and learn how do we accept and reject the
alert depending upon the alert types.
4 Types of Alerts in Selenium
1) Simple Alert
 The simple alert class in Selenium displays some information or warning on the
screen.
5 Types of Alerts in Selenium
2) Prompt Alert
 This Prompt Alert asks some input from the user and Selenium webdriver can enter
the text using sendkeys(” input…. “).
6 Types of Alerts in Selenium
3) Confirmation Alert
 This confirmation alert asks permission to do some type of operation.
7 How to handle Alert in Selenium WebDriver?

Alert interface provides the below few methods which are widely used
in Selenium Webdriver.
 1) void dismiss() // To click on the ‘Cancel’ button of the alert.

 2) void accept()// To click on the ‘OK’ button of the alert.

 3) String getText() // To capture the alert message.


8 How to handle Alert in Selenium WebDriver?

 4) void sendKeys(String stringToSend) // To send some data to alert


box.

 In the next slide: You can see a number of Alert methods are displayed by
Eclipse.
 We can easily switch to alert from the main window by using
Selenium’s .switchTo() method.
9 How to handle Alert in Selenium WebDriver?
10 How to handle Alert in Selenium WebDriver?
 Now we automate the given below scenario.
 In this scenario, we will use Guru99 demo site to illustrate Selenium Alert handling.
 Step 1) Launch the web browser and open the site
https://demo.guru99.com/test/delete_customer.php
 Step 2) Enter Any Customer id.
11 How to handle Alert in Selenium WebDriver?
 Step 3) After entering the customer ID, Click on the “Submit” button.
12 How to handle Alert in Selenium WebDriver?
 Step 4) Reject/accept the alert.
13 How to handle Alert in Selenium WebDriver?
 Handling Alert in Selenium Webdriver:
14 How to handle Alert in Selenium WebDriver?
15 How to handle Alert in Selenium WebDriver?

 Output:
When you execute the above code, it launches the site. Try to delete Customer ID by
handling confirmation alert that displays on the screen, and thereby deleting customer id
from the application.
How to handle Pop-up window using Selenium
16
Webdriver?
 In automation, when we have multiple windows in any web application, the activity
may need to switch control among several windows from one to other in order to
complete the operation. After completion of the operation, it has to return to the
main window i.e. parent window in Selenium.

 In Selenium web driver there are methods through which we can handle multiple
windows.
 Driver.getWindowHandles();
 To handle all opened windows by web driver, we can use
“Driver.getWindowHandles()” and then we can switch window from one window to
another in a web application. Its return type is Iterator<String>.
 Driver.getWindowHandle();
 When the site opens, we need to handle the main window
by driver.getWindowHandle(). This will handle the current window that uniquely
How to handle Pop-up window using Selenium
17
Webdriver?
 For Window handling in Selenium, we will follow the below steps:
 Now, we will automate the given below scenario to see how to handle multiple
windows using Selenium Webdriver.
 In this scenario, we will use “Guru99” demo site to illustrate window handling.

 Step 1) Launch the site.


Launch the browser and open the site https://demo.guru99.com/popup.php
How to handle Pop-up window using Selenium
18
Webdriver?
 Step 2) Click on link “Click Here”.
When the user clicks on the ” Click Here ” link, new child window opens.
How to handle Pop-up window using Selenium
19
Webdriver?
 Step 3) New Child Window opens.
A new window opens, ask the user to enter email id and submit the page.
How to handle Pop-up window using Selenium
20
Webdriver?
 Step 4) Enter your email ID and submit.
How to handle Pop-up window using Selenium
21
Webdriver?
 Step 5) Display the Access Credentials on submitting the page.
How to handle Pop-up window using Selenium
22
Webdriver?
When you execute the code, you will see the child window is open in new tab.
 1. Close the Child window on which credentials are displayed.
How to handle Pop-up window using Selenium
23
Webdriver?
 2. Switch to the parent window.
24 How to Handle Multiple Windows in Selenium?

 How to Handle Multiple Windows in Selenium


25 How to Handle Multiple Windows in Selenium?
26 How to Handle Multiple Windows in Selenium?
27 How to Handle Multiple Windows in Selenium?
 Output:
When you execute the above
code, it launches the site and
on clicking the link “Click
here,” it opens up a child
window in a new tab. You can
close the child window, and
switch to the parent window
once the operation is
completely done. Hence
handling more than one
window in the application.
How to copy Xpath from Chrome
28
 Assume you have a web element with no ID or name or any other attribute , the only way to get this web element is using xPath
 We Can use Chrome to copy xpath as in picture
 We get the web element tag and right click then copy Xpath
 Now you can use the copied xPath into your Code
29 Conclusion
 We defined the types of alert and shown them with a screen shot.
 Demonstrated handling the Alert with Selenium WebDriver using particular scenario.
 Handled multiple windows with Selenium WebDriver using particular scenario.
Thank You
30

You might also like