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

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

问题描述

我正在尝试在我的一个新 Webdriver 脚本中处理身份验证弹出窗口.我有一个适用于 IE 的有效解决方案,但我在使用 Chrome 时遇到了困难.IE 就像遵循 [this page] 上的建议一样简单:如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口.该线程并没有为 Chrome 显示一个很好的解决方案,尽管一些评论者指出,该解决方案不适用于 Chrome.问题是,当您尝试在 Chrome 上执行以下代码时,登录弹出窗口不是警报.

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天全站免登陆