简体   繁体   English

使用Selenium的完整Internet Explorer身份验证对话框

[英]Complete Internet Explorer Authentication Dialog with Selenium

I am using Selenium to simulate a user to automate some legacy software. 我正在使用Selenium来模拟用户以自动化一些旧版软件。 The software works only with IE6 (I'm using IE11 in compatibility mode) and is a bit crap. 该软件仅适用于IE6(我在兼容模式下使用IE11),有点废话。

There is a point in the software where the Windows Security dialog appears. 在软件中有一点会出现“ Windows安全性”对话框。 This requires credentials before the user/simulator can proceed. 在用户/模拟器可以继续之前,这需要凭据。

I'm using IAlert.SetAuthenticationCredentials to try and populate the dialog but this doesn't seem to work. 我正在使用IAlert.SetAuthenticationCredentials尝试填充对话框,但这似乎不起作用。 To move on from this, I can enter the details manually, but then Selenium seems to thing the main browser window has been closed: 为此,我可以手动输入详细信息,但随后Selenium似乎已关闭了主浏览器窗口:

Currently focused window has been closed. 当前聚焦的窗口已关闭。

The WindowHandles collection at this point is empty, but the browser window is still open, and has rendered the correct page. 此时的WindowHandles集合为空,但浏览器窗口仍处于打开状态,并已呈现正确的页面。

What's going on here? 这里发生了什么?

屏幕截图

UPDATE 更新

The answers provided are suggestions on how to handle the dialog. 提供的答案是有关如何处理对话框的建议。 I'm wondering why Selenium thinks the browser window is closed when in fact it is still there. 我想知道为什么Selenium认为实际上仍然关闭了浏览器窗口。

It is not possible to interract with native windows via selenium . 无法通过selenium与本机窗口进行selenium The way to deal with your issue is for example to use analogue of Robot in Java. 解决问题的方法例如是在Java中使用Robot类似物。 Since you are using C# there is a simulator here https://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library . 由于您使用的是C#因此这里有一个模拟器https://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library

Example code would be like following: 示例代码如下所示:

// Simulate (Ctrl + C) shortcut, which is copy for most applications
KeyboardSimulator.SimulateStandardShortcut(StandardShortcut.Copy);

// This does the same as above
KeyboardSimulator.KeyDown(Keys.Control);
KeyboardSimulator.KeyPress(Keys.C);
KeyboardSimulator.KeyUp(Keys.Control);

There are also Mouse simulators, so with this framework it will be possible to enter the required values in window and accept it. 还有鼠标模拟器,因此使用此框架,可以在窗口中输入所需的值并接受它。

Try to switch to that alert by, 尝试切换到该警报,

var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("Username", "Pwd");
alert.Accept();

I have tested it and it works for IE11, selenium v3.1.0 我已经对其进行了测试,它适用于IE11硒v3.1.0

Ref: https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_IAlert_SetAuthenticationCredentials.htm 参考: https : //seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_IAlert_SetAuthenticationCredentials.htm

Suggesstion 1-Go to internet explorer settings->security settings-> user authentication-> select automatic login with current username and password. 建议1-转到Internet Explorer设置->安全设置->用户身份验证->选择使用当前用户名和密码自动登录。 在此处输入图片说明

Suggesstion 2- if your application has access to it's API, then login via API, get the authentication token and set the auth.token in browser cookie. 建议2-如果您的应用程序有权访问它的API,然后通过API登录,获取身份验证令牌并在浏览器cookie中设置auth.token。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM