selenium中处理windows的windows security dialog,安全验证

最近在做一个测试,需要通过安全验证登陆后台后才能继续后面的操作。



解决办法:

方法一:在URL里面直接加入用户名和密码:

driver.get("https://username:password@monitor.test.com/nagios/");

这样就能直接访问到了!!

方法二:对于IE浏览器需要修改注册表

保存下面内容保存为reg,双击

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE]
"iexplore.exe"=dword:00000000

方法三:借助第三方工具如autoit。


参见这位大神的方法:http://blog.csdn.net/caiqcong/article/details/7600988


方法四:

很不幸,方法一中如果username是domain\username这样的格式,那么\是会被浏览器给解码成%5C这样的。这个时候可以用启动同一个firefox的profile来实现。

具体参考:

http://stackoverflow.com/questions/3021602/http-basic-auth-via-url-in-firefox-does-not-work

For some reason (maybe the ones explained at http://stackoverflow.com/a/14348701/256245), the above solution does not work with newer versions of Firefox. Here is what works for me now (tested with Firefox 19.0.2):

  1. Install AutoAuth Firefox plugin;
  2. Visit the site where the authentication is needed. Enter your username and password and make sure to choose to save the credentials;
  3. Save AutoAuth installation file at your hard drive: at the plugin page, right click at “Add to Firefox” and “Save link as”;
  4. Instantiate Firefox webdriver as following:

    FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
    File pluginAutoAuth = new File("src/test/resources/autoauth-2.1-fx+fn.xpi");
    firefoxProfile.addExtension(pluginAutoAuth);
    return new FirefoxDriver(firefoxProfile);
    

第四步中default可以定制自己一个profile,

File pluginAutoAuth = new File("src/test/resources/autoauth-2.1-fx+fn.xpi");
firefoxProfile.addExtension(pluginAutoAuth);

这两句经实践是可以去掉的,因为第一行中是那个default的profile中是有安装这个插件的。

插件地址:https://addons.mozilla.org/en-us/firefox/addon/autoauth/

这个问题其实讨论也很多,以下一些地址保存后续参考用:

https://code.google.com/p/selenium/issues/detail?id=34

http://stackoverflow.com/questions/11522434/how-to-handle-login-pop-up-window-using-selenium-webdriver

http://sqa.stackexchange.com/questions/2277/using-selenium-webdriver-with-windows-authentication

http://stackoverflow.com/questions/12151958/login-popup-window-using-selenium-webdriver




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值