0

enter image description hereI am trying to access a website, However to access the website first I need to enter username and password, After that full website will get open. When I try to send username and password through "alert.sendkeys", it gives error "No alert open". Please note website will only open when you have put the username and password first and then click on "Sign In" for authorization.My browser is chrome, version:64 and chrome driver version is :2.38. Here is my code:

public static void launchWebsite(String URL) {
        driver.get(URL);
        try {
            WebDriverWait wait = new WebDriverWait(driver, 2);
            wait.until(ExpectedConditions.alertIsPresent());
            Alert alert = driver.switchTo().alert();
            System.out.println(alert.getText());
           alert.sendKeys("website");
           alert.sendKeys("grren");

        } catch (Exception e) {
            System.out.println("No alertis present");
            //exception handling
        }
    }

1 Answers1

1

driver.get("http://UserName:Password@Example.com"); should do the trick if the site uses basic authentication.

Special note: if you have @ in your password, don't forget to replace that bad boy by a %40

In case your authentication server requires username with domain like "domainuser" you need to add double slash / to the url: //localdomain\user:password@example.com

EDIT:

Chrome 59 has removed support for https://user:password@example.com URLs.

You can use the following method to handle it in IE as of selenium 3.4

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

There is way of handling this using Chrome extension. More explanation can be found here

OR

Downgrade your chrome version to <59

GPT14
  • 809
  • 6
  • 13