如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口 [英] How to handle authentication popup with Selenium WebDriver using Java

查看:63
本文介绍了如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码处理身份验证弹出窗口:

FirefoxProfile profile = new FirefoxProfile();profile.setPreference("network.http.phishy-userpass-length", 255);profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "x.x.x.x");驱动程序 = 新的 FirefoxDriver(配置文件);baseUrl="http://" + 登录名 + ":" + 密码 + "@" + url;driver.get(baseUrl + "/");

当我执行测试时,页面会显示身份验证弹出窗口并仍在加载,直到我单击取消按钮.那一刻,我可以进入下一个页面,这意味着身份验证成功但仍然总是显示身份验证弹出

解决方案

警报方法,authenticateUsing() 让您跳过 Http 基本身份验证 盒子.

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

<块引用>

Selenium 3.4 开始,它仍处于测试阶段

现在只为 InternetExplorerDriver

实现

I'm trying to handle authentication popup using the code below:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.phishy-userpass-length", 255);
profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "x.x.x.x");
driver = new FirefoxDriver(profile);
baseUrl="http://" + login + ":" + password + "@" + url;
driver.get(baseUrl + "/");

When I execute the test, the page shows the authentication popup and still loading for a until I click cancel button. A that moment, I can access to the next page ,this mean that the authentication success but still always show the authentication popup

解决方案

The Alert Method, authenticateUsing() lets you skip the Http Basic Authentication box.

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

As of Selenium 3.4 it is still in beta

Right now implementation is only done for InternetExplorerDriver

这篇关于如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆