所以我正在使用Selenium Webdriver。在运行Windows 7的计算机上,我可以使用
处理Windows安全性弹出窗口driver.switchTo().alert().authenticateUsing(new UserAndPassword([Credentials]));
但在Windows 10中,我不能。程序不会将其识别为警报,只是暂停直到它终止。我试过研究类似的问题,但没有运气。这仍然适用于IE,而不是Edge。
答案 0 :(得分:0)
I have work around, might be helpful here. Let me make some comments:
1. Selenium does not have capacity to handle IE "Windows Security" pop up.
Not even through "switch alert accept/ dismiss" concept.
2. You have to use third party tools such as AutoIT, this is what I used to handle IE pop up. But this tool has some limitations such as you can not lock you automation machine so you have to keep you test machine unlocked while test is in progress because of security reason (you can google it about).
3. Currently you can not even lock you machine while running IE Selenium Automation
Work around is here :
you may follow this link : http://learn-automation.com/handle-windows-authentication-using-selenium-webdriver/
观看视频:https://www.youtube.com/watch?v=civzNtKTCD0&t=862s
1. Download AutoIT
2. Write up script using AutoIT editor
3. should like this for IE scenario:
WinWaitActive("Windows Security")
Send("username")
Send("{TAB}")
Send("password")
Send("{TAB}")
Send("{TAB}")
Send("{ENTER}")
4. Save it and right click -> compile it using 64 bit
5. now you will have a one exe , which can be used directly in your selenium code , for example :
driver = new InternetExplorerDriver(DrivePath);
driver.Manage().Window.Maximize(); System.Diagnostics.Process.Start(@"C:\Users\source\HandleAuthentication.exe"); driver.Navigate().GoToUrl(url);
答案 1 :(得分:0)
以下策略与IE安全设置一起对我有用
`UserAndPassword UC = new UserAndPassword(userName, password);
driver.switchTo().alert().authenticateUsing(UC);`
答案 2 :(得分:0)
最初,我一直在使用Windows 10 IE 11中的Windows安全警报进行挣扎。我尝试使用AutoIT(无法识别警报),SwitchToAlert,AuthenticateUsing,在URL中传递UID和PWD等,但是它们对我不起作用。最后,在Selenium中使用Sikuli成功了。下面是代码片段:
Screen s=new Screen();
//If you need to pass UID please add one more line of code here. For me only PWD field to fill.
s.type("PasswordField.png","Password");
s.find("Ok.png");
s.click("Ok.png);
如果在输入凭据之前应用程序一直保持加载状态,则在执行Sikuli脚本之前,您将获得pageLoadTimeout
异常。为了克服此异常,我尝试了以下代码,并且可以正常工作:
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
try{
driver.get("URL");
} catch (TimeoutException e){
Screen s=new Screen();
s.type("PasswordField.png","Password");
s.find("Ok.png");
s.click("Ok.png);
}
答案 3 :(得分:0)
您可以使用Raj的答案,但不需要使用Sikuli框架。您可以使用java.awt.Robot将击键发送到Windows安全弹出窗口。在下面的示例中,机器人将用户ID键入“ U”,然后跳至密码框,键入密码“ P”,然后键入Enter键以关闭弹出窗口。
Robot robot = new Robot();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
try{
driver.get("URL");
} catch (TimeoutException e){
robot.keyPress(KeyEvent.VK_U);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_P);
robot.keyPress(KeyEvent.VK_ENTER);
}
希望它会为您提供帮助。
答案 4 :(得分:-3)
我能够通过更改注册表来解决IE 11(Windows 10)中的IE Basic Auth问题。如this blog post中所述,需要在以下位置创建iexplore.exe
和explorer.exe
个键:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE
它们应为DWORD
值,设置为0.
这样你就可以:
http://domain%5Cuser:password@example.com
其中%5C
为\
。