1

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

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

When I execute the test, the page shows the authentication popup and cursor is continuously blinking on User Name. And not proceeding further. After 10 seconds I am getting time out exception org.openqa.selenium.TimeoutException

Complete exception: Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for alert to be present

I have tried by increasing time out period to 100. Also tried by adding Thread.sleep statement But it wont work

monil
  • 37
  • 1
  • 8

1 Answers1

0

The approach I've used very successfully is to set up an embedded Browsermob proxy server (in Java code) and register a RequestInterceptor to intercept all incoming requests (that match the host / URL pattern in question).

When you have a request that would otherwise need Basic auth, add an Authorization HTTP header with the credentials required ('Basic ' + the Base64-encoded 'user:pass' string. So for 'foo:bar' you'd set the value Basic Zm9vOmJhcg==)

Start the server, set it as a web proxy for Selenium traffic, and when a request is made that requires authentication, the proxy will add the header, the browser will see it, verify the credentials, and not need to pop up the dialog.

You won't need to deal with the dialog at all. Another benefit is that because it's a pure HTTP solution, it works the same across all browsers and operating systems.

Community
  • 1
  • 1
Andrew Regan
  • 4,887
  • 6
  • 35
  • 67