Lab 6 - Handling Alerts and Pop Ups
Lab 6 - Handling Alerts and Pop Ups
1 Lab 6
Handling Alerts and Popups
2 Agenda
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.
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.