Perform authentication using Chrome or Firefox
Windows OS authentication pop-up window is not accessible via standard Selenium tools. When using Chrome or Firefox, you can use the following code based on Perfecto visual functions.
Copy
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);
}
Related Articles
See also the Perfecto Knowledgebase.