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

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

问题描述

我正在尝试在一个新的Webdriver脚本中处理身份验证弹出窗口.我有一个适用于IE的有效解决方案,但我在Chrome方面苦苦挣扎. IE就像按照[本页]的建议一样简单:

I am trying to handle an authentication pop-up in one of my new Webdriver scripts. I have a working solution for IE, but I am struggling with Chrome. IE was as simple as following the advice on [this page]:How to handle authentication popup with Selenium WebDriver using Java. That thread doesn't show a great solution for Chrome, although several commentors point out, that the solution does not work for Chrome. The problem is, when you try to do the below code on Chrome, the login popup isn't an Alert.

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

这不是Windows级别()身份验证弹出窗口,网页仅受密码保护.我知道在Stack Overflow上还有这个问题的其他几个实例,但是最近不到2年了.我希望在2017年能有更好的解决方案.在此先感谢.

It's not a windows level () authentication pop-up, the web page is simply password protected. I know there are several other instances of this question on Stack Overflow, but I don't see any more recently than 2 years old. I am hoping there is a better solution now in 2017. Thanks in advance.

推荐答案

* edit Chrome不再支持此功能.

不是可以通过在地址前添加用户名和密码来处理受限制的"弹出窗口吗?

Isn't that a "restricted" pop-up that can be handled by prepending the address with username and password?

代替driver.get("http://www.example.com/");进入driver.get("http://username:password@www.example.com");.

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

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