selenium如何解决window安全验证问题

时间:2023-11-22 16:02:32

解决办法

IE浏览器:

1.使用autoit,捕捉到控件后,编写au3脚本,生成exe,然后java调用exe

au3脚本

Dim $account = "username"
Dim $pwd = "password"
Dim $dialogTitle = "Windows 安全"
WinActivate($dialogTitle)
WinWaitActive($dialogTitle)
Sleep(*)
ControlSetText($dialogTitle,"","Edit1",$account)
Sleep(*)
ControlSetText($dialogTitle,"","Edit2",$pwd )
ControlClick($dialogTitle,"","Button2")
Sleep(*)

java调用代码,可以自行把绝对路径改成相对路径

        Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec("\"D:/workspace/test.exe\"");
} catch (Exception e) {
System.out.println("Error exec!");
}

2.更改注册表

保存下面内容保存为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

火狐浏览器

在地址前面加上用户名和密码,如:http://username:password@127.0.0.1:8888/index

参考资料:http://m.blog.csdn.net/blog/lan0227/36384201

http://blog.csdn.net/max229max/article/details/34456507