在Selenium中自动执行身份验证弹出窗口 [英] Automating Authentication popup in Selenium

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

问题描述

我在chrome浏览器中自动弹出身份验证时遇到了一些麻烦. 我正在使用名为" http://the-internet.herokuapp.com/basic_auth"

I am struggling a bit while automating an authentication pop up in the chrome browser. I am using this test site named "http://the-internet.herokuapp.com/basic_auth"

这是我的代码.

public class Authen {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub

         System.setProperty("webdriver.chrome.driver", "C:\\Users\\Sumedha\\OneDrive\\Documents\\Selenium\\Drivers\\chromedriver_win32\\chromedriver.exe");
          WebDriver driver = new ChromeDriver();
driver.get("http://the-internet.herokuapp.com/basic_auth");
     Runtime.getRuntime().exec("C:\\Users\\Sumedha\\OneDrive\\Documents\\Selenium\\AutoIT\\handleauthentication.exe");   
    }
}

这是我的autoIT脚本的外观.

This is how my autoIT script looks.

WinWaitActive("Sign in")
Send("admin")
Send("{TAB}")
Send("admin")
Send("{ENTER}")

现在,当我运行此命令时,不会在弹出窗口中输入凭据,并且脚本也不会运行.

Now when I run this, credentials are not entered in the popup and script does not run at all.

请帮助!

预先感谢.

推荐答案

正如cruisepandey所写,只能将基本身份验证凭据直接添加到url

as cruisepandey writes, only Basic Authentication credentials can be added direct into the url

其中某些凭据警报不是浏览器的组件,而是操作系统的组件.

where as some credential alerts are not browser's component, but OS's.

无法通过硒访问这些弹出窗口,如果可能的话,恶意软件可能会渗透进来.

those pop-ups are not accessible via selenium, a malware could penetrate if it would be possible.

BasicAuthentication将您的凭据直接发送到URL:https://{username}:{password}@host.com

BasicAuthentication put your credentials direct to URL: https://{username}:{password}@host.com

具有手动输入的凭据的OAuth需要基于UIAutoamtion的工具,例如: AutoIT Python uiautomation .

OAuth with Manually entered Credentials need a UIAutoamtion based tool, some examples: AutoIT or Python uiautomation.

这篇关于在Selenium中自动执行身份验证弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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