如何切换到窗口身份验证弹出窗口并输入凭据? [英] How to switch to window authentication popup and enter credentials?

查看:216
本文介绍了如何切换到窗口身份验证弹出窗口并输入凭据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开应用程序URL后,用户将被重定向到登录页面,其中有一个登录按钮。

After opening application URL, User is redirected to Sign-In page where there is a Sign-In button.

driver.get("abc.com")

现在,当用户点击登录按钮时,URL为在同一窗口中更改说它变为xyz.com并显示用于登录目的的身份验证弹出窗口,类似于下面显示的图像。

Now when user click on Sign-In button, URL is changed in the same window say it becomes xyz.com and shows authentication popup window for login purpose similar to image shown below.

要在身份验证窗口中输入用户名和密码,我尝试了下面的代码

To enter username and password in authentication window I tried the below code

shell = win32com.client.Dispatch("WScript.Shell")
shell.Sendkeys("username")
time.sleep(1)
shell.Sendkeys("{TAB}")
time.sleep(1)
shell.Sendkeys("password") 
time.sleep(1)
shell.Sendkeys("{ENTER}")
time.sleep(1)



<它没有用。然后我尝试使用上面的代码直接打开Windows身份验证弹出窗口(通过点击登录按钮后复制URL),它工作了

It didn't work. Then I tried to open windows authentication popup directly(by copying URL after click of Sign-In button) with the above code, it worked

driver.get("xyz.com")//instead of abc.com my application URL

我有点困惑。如果我打开我的应用程序URL abc.com,单击登录按钮,使用autoit,它不会输入凭据。但是,如果我直接发送窗口身份验证URL xyz.com而不是app URL abc.com并使用autoit,它就可以工作。

I am bit confused. If I open my app URL abc.com, click on Sign-In button, use autoit, it didn't enter credentials. But if I directly send window authentication URL xyz.com instead of app URL abc.com and use autoit, it work.

有人可以建议我在这里缺少什么吗?我也尝试在点击Sign-In按钮后切换窗口,考虑其新的URL然后自动命令,但它仍然无效。

Can anyone suggest what I am missing here? I also tried to switch window after click on Sign-In button thinking its new URL and then autoit command, but it still it didn't work.

driver.switch_to_window(driver.window_handles[1])

对此有什么想法吗?

注意:我注意到点击登录按钮,窗口无限加载&光标在Windows身份验证poup的用户名text-field上处于活动状态。此外,一旦出现Windows身份验证窗口,selenium命令都没有工作,也没有自动命令。

Note: I noticed that click on Sign-In button, windows is loading infinitely & cursor is active on username text-field of windows authentication poup. Also once windows authentication window appears, none of selenium command is working and neither autoit command.

推荐答案

该对话框被视为警报由硒。在c#中,输入Firefox测试凭据的代码如下所示:

The dialog is treated as an alert by selenium. In c#, the code to enter in credentials for a Firefox test looks like:

// Inputs id with permissions into the Windows Authentication box
var alert = driver.SwitchTo().Alert();
alert.SendKeys( @"username" + Keys.Tab + 
                @"password" + Keys.Tab);
alert.Accept();

第一行告诉驱动程序检查打开的警报(对话框)。

The first line is telling the driver to check for open alerts (the dialog box).

第二行将用户名和密码发送到警报

The second line sends the username and password to the alert

第三行然后发送这些凭证,假设它们是有效,测试将继续。

The third line then sends those credentials and, assuming they are valid, the test will continue.

假设您正在使用Firefox进行测试,则无需使用额外的框架来处理此身份验证框。

Assuming you are testing using Firefox, there is no requirement to use extra frameworks to deal with this authentication box.

这篇关于如何切换到窗口身份验证弹出窗口并输入凭据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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