
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Different Ways of Handling Authentication Popup Window Using Selenium
We can handle authentication pop-up window using Selenium webdriver by incorporating the username and password within the application URL. The format of an URL along with credential should be − https://username:password@URL
Let us launch a web page having the authentication pop-up generated at page load −
The user Name and Password fields are having value as admin.
If we ignore this pop-up on clicking the Cancel button, we shall be navigated to the below page.
If proper credentials are entered and then the OK button is clicked, we shall be navigated to the below page.
In the above example, to handle the authentication pop-up, using the get method, the URL to be passed as a parameter should be - https://admin:admin@the−nternet.herokuapp.com/basic_auth.
Example
from selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") #implicit wait driver.implicitly_wait(0.5) #maximize browser driver.maximize_window() #username, password value p = "admin" #url format url = "https://" + p + ":" + p + "@" + "the-internet.herokuapp.com/basic_auth" #launch URL driver.get(url) #identify element l = driver.find_element_by_tag_name("p") #obtain text s = l.text print("Text is: ") print(s) #close browser driver.close()