How to handle "Authentication Required" Popup in Selenium
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 to share
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 to share