1
votes

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

3
No, its not duplicate. The solution of passing credential in URL does not work for me... I am using python 2.7.12 and latest chrome and latest chrome driver - Shoaib Akhtar
It's hard to say why it's no longer working without a reproducible example. Why not provide the credentials in the URL or with an injected XMLHttpRequest ? - Florent B.
@FlorentB. Regarding XMLHttpRequest do you have any example or link to it. And regarding providing credential in url also does not work stackoverflow.com/questions/40671662/… - Shoaib Akhtar
@Shoaib Akhtar, providing the credentials in the URL is possible with Chrome when the URL is composed of the domain only without any path. Your link points to an issue with Firefox, not Chrome. - Florent B.

3 Answers

1
votes

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.

1
votes

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
0
votes

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