Windows authentication code no longer working now

社会主义新天地 提交于 2019-12-29 09:18:26

问题


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:\Python27\lib\site-packages\comtypes\gen\__init__.pyc'>
2018-04-02 07:09:28,230 INFO: Using writeable comtypes cache directory: 'C:\Python27\lib\site-packages\comtypes\gen'

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


回答1:


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.




回答2:


Try AutoIT to create an exe for the windows authentication and call it where ever required, if nothing else is working. If you are mostly working with Pyton then try this

Sample code:-

WinWaitActive("Authentication Required","","120")

If WinExists("Authentication Required") Then
Send("username{TAB}")

Send("password{Enter}")

EndIf



回答3:


You could try automating the keyboard directly?? It might work. You automate the keyboard.

Answered a similar question here - https://stackoverflow.com/a/49109132/6003362



来源:https://stackoverflow.com/questions/49491048/windows-authentication-code-no-longer-working-now

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!