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

Last updated: Dec 18, 2019 18:13

Problem

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

Solution

When using Chrome or Firefox the following code based on Perfecto visual functions can be used:

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


    public static void chrome_firefoxAuthTest(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 = "Sign in";
        driver.executeScript("window.open('"+ url +"','_blank');");
        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");
        params.put("label.direction", "right");
        params.put("text", password);
        driver.executeScript("mobile:edit-text:set", params);
        params.clear();
        params.put("label", indentifier);
        params.put("label.direction", "inside");
        params.put("index", 2);
        driver.executeScript("mobile:button-text:click", params);
    }