How to handle "Authentication Required" Popup in Selenium

Is it possible to handle the "Authentication Required" popup in selenium that has "UserName" and "Password" fields with Alert.

enter image description here

+6


source to share


4 answers


You can check the warning popup. for this you need to import the following,

import org.openqa.selenium.security.UserAndPassword;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

      

First you need to wait until this popup appears.

WebDriverWait wait = new WebDriverWait(driver, 30);

      

Then check for the presence / visibility of the alert popup.



Alert alertPopUp = wait.until(ExpectedConditions.alertIsPresent()); 

      

Then you can use the authenticateUsing method for the selenium web driver.

alertPopUp.authenticateUsing(new UserAndPassword("your_username", "your_password"));

      

There is also another way to quickly check if you just want to acknowledge the alert

try {
  Alert alert = driver.switchTo().alert();
  alert.accept();

 } catch (NoAlertPresentException e) {
   // Alert not available
   e.printStackTrace();
 }

      

0


source


I got this working in IE using the below code:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Ie()
driver.get("https://scdm.corp.vha.com")
alert = driver.switch_to_alert()
alert.authenticate("username","password")
time.sleep(20)
driver.close()

      

0


source


I recently ran into this problem when testing the pop-up window " Normal authentication Internet" . Decision

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

Add username and password in the url itself. I tried it in Chrome and Firefox works.

0


source


Instead of using AutoIt for authentication, you can simply do this

driver.get(http://Username:Password@SiteURL)  

      

0


source







All Articles