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()