Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle authentication popup with Selenium WebDriver using Java

I'm trying to handle authentication popup using the code below:

FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.http.phishy-userpass-length", 255); profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "x.x.x.x"); driver = new FirefoxDriver(profile); baseUrl="http://" + login + ":" + password + "@" + url; driver.get(baseUrl + "/"); 

When I execute the test, the page shows the authentication popup and still loading for a until I click cancel button. A that moment, I can access to the next page ,this mean that the authentication success but still always show the authentication popup

like image 560
Imen CHOK Avatar asked Jun 19 '14 10:06

Imen CHOK


People also ask

How does Selenium handle authentication required pop up?

Handling login pop-up in Selenium by passing the credential in URL. The Basic authentication pop-up is like the alert pop-up . When we navigated to a specific web page that asks for the credential. To handle this, we can pass credentials (Username + Password) to the web page's URL.

How do I pass authentication credentials in Selenium?

Pass username and password in the URL Passing username and password in the URL helps to avoid the login prompt. This is achieved by encoding the username and password in the URL, that is, prepending username:password@ to the hostname in the URL.


2 Answers

The Alert Method, authenticateUsing() lets you skip the Http Basic Authentication box.

WebDriverWait wait = new WebDriverWait(driver, 10);       Alert alert = wait.until(ExpectedConditions.alertIsPresent());      alert.authenticateUsing(new UserAndPassword(username, password)); 

As of Selenium 3.4 it is still in beta

Right now implementation is only done for InternetExplorerDriver

like image 157
Prashanth Sams Avatar answered Oct 09 '22 23:10

Prashanth Sams


Don't use firefox profile and try below code:

driver.get("http://UserName:[email protected]"); 

If you're implementing it in IE browser, there are certain things which you need to do.

In case your authentication server requires username with domain like "domainuser" you need to add double slash / to the url:

//localdomain\user:[email protected] 
like image 36
Raghav Arora Avatar answered Oct 09 '22 22:10

Raghav Arora