[英]How to handle authentication required pop up in next tab in selenium webdriver using java?
In Chrome, clicking a certain link opens a new tab with an "Authentication Required" popup. 在Chrome浏览器中,点击某个链接会打开一个新标签,其中弹出“需要身份验证”。 As you can see, it has 'User name' and 'password' with 'Log In' and 'Cancel' buttons.
如您所见,它具有“用户名”和“密码”以及“登录”和“取消”按钮。
With Java code, how can I enter values (user name and password) in this popup? 使用Java代码,如何在此弹出窗口中输入值(用户名和密码)? Because I can't get the locator of username and password, also the alert method is not working here.
因为我找不到用户名和密码的定位器,所以警报方法在这里也不起作用。
The code I tried: 我试过的代码:
public static void switchToalert() {
driver.switchTo().alert();
// Selenium-WebDriver Java Code for entering Username & Password as // below:
driver.findElement(By.id("Username")).sendKeys("userName");
driver.findElement(By.id("Password")).sendKeys("myPassword");
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
}
Thanks Govind 谢谢戈文德
Handle Windows Authentication using Selenium Webdriver 使用Selenium Webdriver处理Windows身份验证
http://username:password@yourWebURL
##example##
http:
//GuravPraveen:Passwrd123@YourURL
driver.get("http://GuravPraveen:Passwrd123@www.xyz.com/signin");
The approach I've used very successfully is to set up an embedded Browsermob proxy server (in Java code) and register a RequestInterceptor
to intercept all incoming requests (that match the host / URL pattern in question). 我非常成功地使用的方法是设置一个嵌入式的Browsermob代理服务器(使用Java代码)并注册一个
RequestInterceptor
来拦截所有传入的请求(与所讨论的主机/ URL模式匹配)。
When you have a request that would otherwise need Basic auth, add an Authorization
HTTP header with the credentials required ('Basic ' + the Base64-encoded 'user:pass' string. So for 'foo:bar' you'd set the value Basic Zm9vOmJhcg==
) 当您有一个本来需要基本身份验证的请求时,请添加带有所需凭据(“ Basic” + Base64编码的“ user:pass”字符串的
Authorization
HTTP标头。因此,请为“ foo:bar”设置值) Basic Zm9vOmJhcg==
)
Start the server, set it as a web proxy for Selenium traffic , and when a request is made that requires authentication, the proxy will add the header, the browser will see it, verify the credentials, and not need to pop up the dialog. 启动服务器,将其设置为Selenium通信的Web代理,并且在发出需要身份验证的请求时,代理将添加标头,浏览器将看到标头,验证凭据,而无需弹出对话框。
You won't need to deal with the dialog at all. 您根本不需要处理该对话框。 Another benefit is that because it's a pure HTTP solution, it works the same across all browsers and operating systems.
另一个好处是,由于它是纯HTTP解决方案,因此在所有浏览器和操作系统上都可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.