0

I need to open a site that contain authentication alert. To handle that alert I tried following code but no success:

try {
    WebDriverWait wait = new WebDriverWait(driver, 100);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
     alert.authenticateUsing((Credentials) new UsernamePasswordCredentials("username", "pass"));
} catch (Exception e) {
    System.out.println("Alert not found");
}

Exception occur is:

Expected condition failed: waiting for alert to be present (tried for 100 second(s) with 500 MILLISECONDS interval)

enter image description here

Rabia Asif
  • 298
  • 3
  • 14

1 Answers1

0

Authentication is not a popup and we can use AutoIT or Sikuli to automate this. But this is tedious task and fortunately we are having another simple solution. The idea is to pass the username and password along with the url.

For Eg.., to pass the username and password, the URL would be http://username:password@url

Selenium Java code:

driver.get("http://USERNMAE:PASSWORD@YOUR_URL");

Hope this helps you. Thanks.

santhosh kumar
  • 1,981
  • 1
  • 9
  • 28