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

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

问题描述

我试图使用来处理身份验证弹出低于code:

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

推荐答案

警报方法, authenticateUsing()让你跳过 HTTP基本身份验证框。

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

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

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