Python+Selenium+IE遇到windows security弹出框

本文介绍了解决在使用Selenium WebDriver进行自动化测试时遇到的IE浏览器HTTPS安全弹窗问题的方法。通过修改注册表中特定键值,可以禁用IE的HTTP用户名密码弹出框,实现自动登录功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

driver.get(url)的时候遇到了https的Windows security弹出框,
解释问题图片网上查了很多解决方案,试了好用的
https://stackoverflow.com/questions/43666687/how-to-handle-windows-security-pop-up-in-ie-windows-10-using-selenium,即:
I was able to solve the IE Basic Auth Problem in IE 11 (Windows 10) by making registry changes. As described in this blog post, iexplore.exe and explorer.exe keys need to be created in the following locations:

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

They should be DWORD values, set to 0.

This will allow you to do:

http://domain\user:password@example.com
where %5C is .
比较简单,修改注册表之后重启机器就可以了,另外\要用/5c代替。
但是我不明白错误原因,也就不明白为什么要这么改。望多指教。
看也有其他方案,但是感觉太麻烦就没试:
https://stackoverflow.com/questions/27322871/handling-authentication-required-alert-box-with-python-2-7-selenium-webdrive
https://stackoverflow.com/questions/48229446/python-selenium-webpage-with-windows-security
https://www.jianshu.com/p/c1397ccde04b
以下是我测试过的用例

#!/usr/bin/env python3
#login site

import selenium.webdriver
# from selenium.webdriver.common.keys import Keys
# from selenium.webdriver.common.alert import Alert
#from selenium.webdriver.support.ui import WebDriverWait as wait
#from selenium.webdriver.support import expected_conditions as EC

br=selenium.webdriver.Ie()
url=r'https://sea%5ctuser1:12345678@home.world.com/'#改注册表之后好用了,而且\要用%5c的方式
br.get(url)#open url
br.implicitly_wait(5)
login=br.find_element_by_id('overridelink')
br.implicitly_wait(10)
login.click()

#wait(br,10).until(EC.alert_is_present())
#alert=br.switch_to_alert()
#alert.send_keys('''sea\\tuser1\ue00412345678''')#user和password一直在username框里,使用Keys.TAB和\t和\ue004也不好用
#alert.send_keys('\t')
#alert.send_keys(Keys.TAB)#不起作用
#alert.send_keys(Keys.TAB)#不起作用
#alert.accept()
Dim wsh Dim CurHour '当前时 Dim CurMinute '当前分 Dim CurSecond '当前秒 '定义常量 Const ObjHour = 17 '时 0-23 Const ObjMinute = 14 '分 0-59 Const ObjSecond = 00 '秒 0-59 WScript.Sleep 20000 ' 延时 20 秒 set wshshell=CreateObject("wscript.shell") ' 创建并设置运行界面窗口 Set objWnd = wshshell.Exec("mshta.exe ""about:<title>running</title><body bgcolor=white><center><h1>Running</h1><p>Automatically press the TAB key every 3 minutes.<br> Please Close window to stop running</p></center><script>window.resizeTo(800,400);window.moveTo((screen.width-800)/2,(screen.height-400)/2);</script>""") set wshshell=CreateObject("wscript.shell") browserPath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" ' 浏览器的绝对路径 url1 = "http://192.168.10.81/decision/view/form?viewlet=%25E5%2588%25B6%25E9%2580%25A02%25E9%2583%25A8%252F%25E7%25AC%25AC3%25E5%2588%25B6%25E9%2580%25A0%25E7%25A7%2591%252F%25E7%25AC%25AC3%25E5%2588%25B6%25E9%2580%25A0%25E7%25A7%2591%25E4%25BA%25BA%25E5%2591%2598%25E7%25AE%25A1%25E7%2590%2586%25E6%259D%25BF%252F%25E7%25AC%25AC3%25E5%2588%25B6%25E9%2580%25A0%25E7%25A7%2591%25E4%25BA%25BA%25E5%2591%2598%25E7%25AE%25A1%25E7%2590%2586%25E6%259D%25BF.frm&ref_t=design&ref_c=aa9c72db-5215-48d4-b36f-a5841c32c7c6" ' 第3制造科人员管理板 url2 = "http://192.168.154.11:4000/gridWebAndon/revoAssembly_Allparts" ' #12总装安东页面 url3 = "http://192.168.154.11:5000/gridWebAndon/revoAllparts" ' #12加工安东页面 wshshell.Run Chr(34) & browserPath & Chr(34)& " " & Chr(34)& url1 & Chr(34) wshshell.Run Chr(34) & browserPath & Chr(34)& " " & Chr(34)& url2 & Chr(34) wshshell.Run Chr(34) & browserPath & Chr(34)& " " & Chr(34)& url3 & Chr(34) WScript.Sleep 20000 ' 延时 20 秒 i = 5 do while(i>0) windowTitle = wshShell.AppActivate("Microsoft Edge") wScript.Sleep 200 wshShell.SendKeys "% " wScript.Sleep 200 wshShell.SendKeys "r" i = i-1 loop 'MsgBox windowTitle WScript.Sleep 100 ' 延时 0.1 秒 wshShell.SendKeys "{esc}" WScript.Sleep 100 ' 延时 0.1 秒 wshshell.SendKeys "{F11}" WScript.Sleep 5000 ' 延时 5 秒 wshshell.SendKeys "{F5}" ' 当窗口关闭时退出循环 do While (objWnd.Status = 0) CurHour = Hour(Now) CurMinute = Minute(Now) CurSecond = Second(Now) WScript.Sleep 60000 ' 切换延时60秒 if CurHour = ObjHour and CurMinute >= ObjMinute then CreateObject("Wscript.Shell").run "cmd.exe /c shutdown -s -f" end if wshshell.SendKeys "^{TAB}" Loop ' 退出脚本 WScript.Quit 删除关机
最新发布
08-09
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值