Authentication Popup

In Previous section, we have discussed about the Frame handling in Selenium Python. In this tutorial, we will discuss more about another Popup which is known as Authentication Popup.

Objectives:

  • What is Authentication Popup
  • How to handle Authentication Popup
  • Practical Example

What is Authentication Popup:

To understand more just visit this demo site ( http://the-internet.herokuapp.com/basic_auth ).

Once you visit this link you will see the popup showing on the top asking for user name and password. This is called Authentication Popup. This is not the Java Script popup. So we cannot use alert and provide the user name and password by using send_keys(). This will not work with this popup. Like other Popup, there is no inspect, id, class etc in this.

Let’s run below code and have a look how this Popup is showing in browsers. For this we will used the “http://the-internet.herokuapp.com/basic_auth” website.

Example:

from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chromeimport ChromeDriverManager
import time

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('http://the-internet.herokuapp.com/basic_auth')
driver.maximize_window()

Output:

Q. How to handle this authentication popup?

There is multiple ways to handle this scenario.There is multiple ways to handle this scenario.

The simple and easiest way to handle this is passing user name and password to the URL. While you open the URL with driver.get then only you need to pass the user name and password as below. For this demo site the user name and password is admin and admin. For this you need to add username:password@ to the beginning of the URL of the website after http://.

driver.get(‘http://admin:admin@the-internet.herokuapp.com/basic_auth’)

Example:

from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chromeimport ChromeDriverManager
import time

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('http://admin:admin@the-internet.herokuapp.com/basic_auth')
driver.maximize_window()

Output:

You can see now the authentication popup is not shown. That mean it opened the authentication popup and passed the user name and password and clicked ok. As this process is very fast. You will not able to observer all this process.

In this way you can handle the Authentication popup in Selenium Python.   This approach may not work with firefox some tome or some application also. There is some other work around called AutoID, SQLi also. It will be the different chapter altogether.

Summary:

  • This is not the Java Script popup. So we cannot use alert and provide the user name and password by using send_keys().
  • The simple and easiest way to handle this is passing user name and password to the URL.
  • While you open the URL with driver.get then only you need to pass the user name and password.
  • For this you need to add username:password@ to the beginning of the URL of the website after http://.
  • This approach may not work with firefox some tome or some application also. There is some other work around called AutoID, SQLi also. It will be the different chapter altogether.

Leave a Reply

Your email address will not be published. Required fields are marked *