Perform authentication using Internet Explorer or Microsoft Edge

Windows OS authentication popup is not accessible via standard Selenium tools.

Solution

When using Internet Explorer or Microsoft Edge, you can use the following code based on Perfecto visual functions:

Copy
ie_edgeAuthTest(driver, "https://jigsaw.w3.org/HTTP/Basic/", "guest", "guest");


public static void ie_edgeAuthTest(RemoteWebDriver driver, String url, String username, String password) throws InterruptedException {
    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)
        .withTimeout(120,TimeUnit.SECONDS)
        .pollingEvery(5,TimeUnit.SECONDS)
        .ignoring(Exception.class);
    String indentifier = "Windows Security";
    driver.executeScript("window.open('"+ url +"','_top');");
    Map<String, Object> params = new HashMap<>();
    params.put("content", indentifier);
    wait.until(_driver -> driver.executeScript("mobile:text:find", params).equals("true"));
    params.clear();
    params.put("label", indentifier);
    driver.executeScript("mobile:button-text:click", params);
    params.clear();
    params.put("label", indentifier);
    params.put("text", username);
    driver.executeScript("mobile:edit-text:set", params);
    params.clear();
    params.put("label", "Password");
    params.put("ignorecase", "case");
    driver.executeScript("mobile:button-text:click", params);
    params.clear();
    params.put("label", indentifier);
    params.put("text", password);
    driver.executeScript("mobile:edit-text:set", params);
    params.clear();
    params.put("label", "OK");
    driver.executeScript("mobile:button-text:click", params);
    Thread.sleep(5000);
}

See also the Perfecto Knowledgebase.