Is it possible to handle "Authentication Required" Pop-up in selenium which having fields as "UserName" and "Password" using Alert.
Asked
Active
Viewed 2.0k times
5
-
5If the authentication pop-up is from HTTP Basic Auth you can send the username and password in the URL: `http://username:password@example.com/`; see also http://serverfault.com/questions/371907/can-you-pass-user-pass-for-http-basic-authentication-in-url-parameters/371918 – rlandster Apr 11 '17 at 06:45
-
Sure but in which programming language? – Billal Begueradj Apr 14 '17 at 07:04
-
@BillalBEGUERADJ I want to handle “Authentication Required” Pop-up in selenium using java programming language. – suchitag Apr 17 '17 at 04:36
-
Check out this post, https://stackoverflow.com/questions/10395462/handling-browser-authentication-using-selenium/10397032#10397032 – Magendhiran V Aug 25 '17 at 15:44
4 Answers
0
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();
}

Sanjay Bhimani
- 1,593
- 1
- 15
- 29
-
1
-
1"authenticateUsing" has been removed since Selenium 3. https://github.com/SeleniumHQ/selenium/issues/6890 – tuan.dinh Feb 21 '19 at 04:37
-
0
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()

SpaghettiCode
- 13
- 1
- 3
0
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.

Mrsreez
- 77
- 12
0
Instead of using AutoIt for Authentication popup you can just do this
driver.get(http://Username:Password@SiteURL)

EzLo
- 13,780
- 10
- 33
- 38

Norayr Sargsyan
- 1,737
- 1
- 12
- 26
-
2
-
It's working for me. Anyway, what you are suggesting to use instead of this? – Norayr Sargsyan Jun 01 '20 at 09:15