简体   繁体   English

如何使用Java处理Selenium Webdriver中下一个选项卡中弹出的所需身份验证?

[英]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身份验证

You can provide credentials in URL itself it means we will add username and password in URL so while running script it will bypass the same 您可以在URL本身中提供凭据,这意味着我们将在URL中添加用户名和密码,因此在运行脚本时它将绕过相同

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.

相关问题 如何使用JAVA在Selenium Webdriver的Internet Explorer中处理服务器身份验证弹出窗口? - How can i handle Server authentication pop-up in Internet Explorer in Selenium Webdriver using JAVA? 如何处理linkedIn授权使用Java在Selenium Webdriver中弹出? - How to Handle linkedIn authorization Pop up in selenium webdriver using Java? 如何使用Java处理Selenium WebDriver中的弹出窗口 - How to handle Pop-up in Selenium WebDriver using Java 如何使用带有Java的Selenium Webdriver处理允许弹出的Firefox插件 - How do I handle allow pop-up of plug-in for firefox using Selenium Webdriver with Java 如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口 - How to handle authentication popup with Selenium WebDriver using Java 如何使用 Java 使用 Selenium WebDriver 在 Chrome 中处理身份验证弹出窗口 - How to handle authentication popup in Chrome with Selenium WebDriver using Java 如何使用Java中的Selenium WebDriver处理身份验证弹出窗口 - How to handle authentication popup with Selenium WebDriver in Java 出现不可预测的弹出窗口-如何使用Selenium(Java)处理此问题? - Unpredictable Pop up appears - How to handle this using Selenium (Java)? 如何处理Selenium Webdriver / Java中Amazon网站上弹出的鼠标悬停等级 - How to handle mouse over rating pop up in Amazon website in Selenium Webdriver/Java 在 Selenium java 中如何处理弹出窗口 - In Selenium java how to handle the pop up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM