How to Handle "Authentication Required" Pop-up in selenium [duplicate]
You can check for alert popup.for this you need to import 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 that pop up is coming.
WebDriverWait wait = new WebDriverWait(driver, 30);
Then check for alert popup is present/visible or not
Alert alertPopUp = wait.until(ExpectedConditions.alertIsPresent());
Then you can use authenticateUsing method of selenium web driver.
alertPopUp.authenticateUsing(new UserAndPassword("your_username", "your_password"));
There is also anoother way to to quick check,If you want to just verify present of alert
try { Alert alert = driver.switchTo().alert(); alert.accept(); } catch (NoAlertPresentException e) { // Alert not available e.printStackTrace(); }
I got this working in IE using the below code:
from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport timedriver = webdriver.Ie()driver.get("https://scdm.corp.vha.com")alert = driver.switch_to_alert()alert.authenticate("username","password")time.sleep(20)driver.close()
Recently I came across this issue while testing the The-Internet Basic authentication Pop-Up. The solution is
driver.get('http://admin:admin@the-internet.herokuapp.com/basic_auth')
Add the username and password in the URL itself. I tried it in chrome and firefox both are working.