Pop Ups in Selenium Webdriver

In HTML pages we have different kind of pop ups, we will discuss about them in this tutorial. Different popups will have different properties.


Types of Pop Ups :

  • Alert Pop Up
  • Confirmation Pop Up
  • Authentication Pop Up
  • Hidden-Division Pop Up
  • Calendar Pop Up
  • Download Pop UP
  • Upload Pop Up

We have different section for Alert and Confirmation Pop Ups, so in this page we are going to discuss how to handle remaining Pop Ups in selenium webdriver

Reading QR Code from website using Webdriver

Authentication Pop Up

When we open password protected pages, we tend to get Authentication pop up. Authentication pop up will have username and password fields, the UI look of the pop up may vary browser to browser

Visit URL selenium webdriver Auth : http://chercher.tech/auth, site expects you to provide credentials

Credentials :
username - selenium
password - webdriver

Authentication Popup : authentication-pop-up-selenium-webdriver

Properties of the Authentication Pop up :
1. Pop up displayed on Page load

2. We can move the pop up (except in chrome)

3. We cannot inspect the pop up with browser inspection tools like (firepath or edv tools)

4. Look varies from browser to browser

Solution to Authentication Pop Up : We have to pass the user name and pass word along with url to handle the authentication pop in selenium webdriver. Please find the syntax to pass the username and password


											driver.get(protocol://Usename:Password@URL Address);
											

Protocols: Http, Https, Ftp,..

To Access the http://chercher.tech/auth page you need to pass username and password like below.


											driver.get(http://selenium:webdriver@chercher.tech/auth);
											

Complete program to handle Authentication popup

											import java.util.concurrent.TimeUnit;
											import org.openqa.selenium.WebDriver;
											import org.openqa.selenium.firefox.FirefoxDriver;
											
											public class AuthenticationPopUp {
												public static void main(String[] args) throws Exception {
													// set the geckodriver.exe property
													System.setProperty("webdriver.gecko.driver", "C:/~/geckodriver.exe");
													// open firefox
													WebDriver driver = new FirefoxDriver();
													driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
													// open webpage
													driver.get("http://selenium:webdriver@chercher.tech/auth");
													// verify the title
													if(driver.getTitle().equals("Authentication Successful")){
														System.out.println("Test Passed");
													}else{
														System.out.println("Test failed");
													}
												}
											}
											

If login is successful you will see below page on the browser. result-authentication-popup-selenium-webdriver



Limitatons:

1. Doesnot work for https protocol
2. It doesnot work when user nam or password contains special characters like : '@' , ':'

Handling Custom Dropdowns in selenium

Hidden division Pop Up

Hidden division pop is nothing but html code which is hidden intially, hidden division pop up also know as dialog or overlay.
Overlay is triggered when application user performs certain taks like clicking a button, submitting form or on page load...


Examples :

1. Calender Popups
2. Contact forms
3. Error and success Messages
hidden-division-modal-selenium-webdriver


Properties of Hidden division Pop up :

1. Cannot be moved here and there
2. We can inspect the overlay
3. This is not java Script popup
4. We can resize and customize the content of the pop up
5. If content is more then the pop up size, pop shows scroll bar
6. When hidden division pop is opened, pop takes the focus from the application.
7. When pop up is closed, focus automatically goes to application
8. Hidden division popup could be nested i.e a hidden division pop can have another hidden division pop up
9. Hidden division pop can hold other pop ups/ alerts on it.


Handle Hidden division Pop Up :

1. Navigate to : http://chercher.tech/practice/hidden-division-popup
2. Click on View Pop-Up button
3. Application opens a Model
inspect-hidden-popup-selenium-webdriver

4. Write xpath for the Name text bar : //input[@type='text']
5. Send text for the Name, using sendKyes in selenium.
6. No Special Operation required to handle hidden division popup.

Complete program for handling hidden division pop up in selenium webdriver


                public class HiddenDivisionPopUp {
                  public static void main(String[] args) throws Exception {
                    // set the geckodriver.exe property
                    System.setProperty("webdriver.gecko.driver", "C:/~/geckodriver.exe");
                    // open firefox
                    WebDriver driver = new FirefoxDriver();
                    driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
                    // open webpage
                    driver.get("http://chercher.tech/practice/hidden-division-popup");
                    // send text to Name field on overlay
                    driver.findElement(By.xpath("//input[@type='text']")).sendKeys("Hidden Division Text");
                  }
                }
              


Even though pop up content is present but pop is not present on UI until we click a button, for this reason it is called as hidden division popup

content-hidden-division-popup-selenium-webdriver



Limitations:

1. We cannot perform operation on webpage until we close pop up, if we try to access selenium throws ElementNotClickable exception

Capture Screenshots in webdriver

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
Copyright © CherCher Tech