Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Dec 18, 2019 19:17

Problem

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

Solution

When using Internet Explorer or Microsoft Edge the following code based on Perfecto visual functions can be used:

          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);
    }