Handle Authentication Popups in Python

Handle Authentication Popups in Python


Hello friend,Iam coming with some new solutions on “How we could handle authentication popups in python”.You know, Selenium is going to be used here to create authentication popups.Mostly Selenium is used with Java Programming Language, But Iam going to give you guys all the solutions in Python and Java both Programming languages.

So guys without any delay, Let’s start out tutorial on how we create a Authentication Popups in Python.


Before we start, we have to understand about HTML pages, In HTML we have a  different kind of pop-ups, In this tutorial, we will discuss about it .

In HTML, we have  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

In HTML, We have a different sections for Alert and Confirmation Pop-Ups. So now , we are going to discuss how to handle remaining Pop-Ups in selenium python programming languages.

Authentication Pop Up with Python in Selenium

When we open a project or website on the brower normally, we mostly seen that a Authenticated popup is shown.Authenticated Popup will have Username and Passowrd fields on the popup.May be UI looks different in browser,It’s depends on browser.

Properties of the Authentication Pop up :-

    • Pop up displayed after Page loaded in the browser
    • We can move the pop up according to the user
    • We cannot inspect the pop up with browser inspection tools like (firepath or devtools)
    • The look varies from browser to browser

First we have to create a Username and Password on it….

Now we have the user name and password along with url to handle the authentication pop in selenium python. We are going touse the below syntax to pass the Userbname and Password :-


Protocols Used : Http, Https, Ftp etc.

To Access the https://xyz.com/auth page you need to pass username and password like below :-


Complete program to handle Authentication popups in python


import unittest
from selenium import webdriver

class Auth(unittest.Auth):
def auth(self):
driver = webdriver.Chrome(executable_path=r'home/PATH/chromedriver');


if(driver.title == "Authentication Successful"):
System.out.println("Confirmed authenticated");
System.out.println("Check Username and Password");

if __name__ == "__main__":


   • Does not work for the https protocol
    • It does not work when the username or password contains special characters like : '@' , ':'

Hidden division Pop Up with Python Selenium

Hidden division pop is nothing but HTML code which is hidden initially, hidden division pop up also known as dialog or overlay.

The overlay is triggered when an application user performs certain tasks like clicking a button, submitting the form or on page load...

Examples :
    • Calendar Popups
    • Contact forms
    • Error and success Messages

Properties of Hidden division Pop up in Python Selenium :-

    • Cannot be moved here and there
    • We can inspect the overlay
    • This is not javaScript popup
    • We can resize and customize the content of the pop-up
    • If the content is more then the pop-up size, pop shows scroll bar
    • When hidden division pop is opened, pop takes the focus from the application.
    • When pop up is closed, focus automatically goes to the application
    • Hidden division popup could be nested for example, a hidden division pop can have another hidden division pop up
   • Hidden division pop can hold other pop-ups/ alerts on it.

Handle Hidden division Pop Up in Python Selenium :-

1.      Click on View Pop-Up button
2.      Application opens a Model
3.      Write XPath for the Name text bar : //input[@type='text']
4.      Send text for the Name, using sendKyes in selenium.
5.      No Special Operation required to handle hidden division popup.

An example program for handling hidden division pop up in selenium python

import unittest
from selenium import webdriver

class Auth(unittest.Auth):
def auth(self):
driver = webdriver.Chrome(executable_path=r'home/PATH/chromedriver');

driver.find_element_by_xpath("//input[@type='text']").send_keys("Hidden Division Text");

if __name__ == "__main__":

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.

Limitations :-

We cannot perform an operation on the webpage until we close the pop up if we try to access selenium throws exception.

I hope you all guys like this tutorial......

Guys if you like this tutorial or this tutorial is helpful to you, then please Share it with your friends……...

                    Other Links 

>>> Speech to Text in Python               >>> Data Structure in Python

>>> CRUD/CURD in Django                   >>> Job Opportunities in Python

>>> Currency Detection By Image in Python         
>>> Pandas Tutorials
>>> Access Network Drive with password in Python   


Post a Comment