Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

python - Windows authentication code no longer working now

My below code for windows authentication was working well for over a year. But for the last few days it is longer working now. I am not able to identify exact reason for that.

from selenium import webdriver
import time
import win32com.client

driver=webdriver.Chrome('D:/Software/BrowsersDriver/ChromeDriver/chromedriver.exe')
driver.maximize_window()
driver.get("authentication windows url")
shell = win32com.client.Dispatch("WScript.Shell")   
shell.Sendkeys("username")  
time.sleep(1)
shell.Sendkeys("{TAB}")
time.sleep(1)
shell.Sendkeys("password") 
time.sleep(1)
shell.Sendkeys("{ENTER}")
time.sleep(5)
driver.quit()

I tried to change my chrome driver to latest when it stops working, but still it is not working. Once the windows authentication appears, cursor keeps blinking on username text-field infinitely, but username is not entered. I am getting below message in console when it is stuck

2018-04-02 07:09:28,230 INFO: Imported existing <module 'comtypes.gen' from 'C:Python27libsite-packagescomtypesgen\__init__.pyc'>
2018-04-02 07:09:28,230 INFO: Using writeable comtypes cache directory: 'C:Python27libsite-packagescomtypesgen'

The same code used to work well earlier. I am using python 2.7.12 and latest version of chrome driver.

Also if someone has a different solution or a link for it for providing credentials in authentication window in python selenium then that too will work for me.

Note: The same code works well earlier, but now it's not working

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Did you try

driver.switchTo().alert();

or

driver.switchTo().activeElement();

before typing credentials?

However, if this works I can't explain why it worked before.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...