Windows身份验证代码现在不再工作



我的以下Windows身份验证代码工作一年多。但是在过去的几天中,现在工作更长。我无法确定这样的确切原因。

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

我试图将我的铬驱动器停止工作时的最新驱动器,但仍然无法正常工作。一旦出现Windows身份验证,光标将不断地闪烁在用户名的文本字段上,但未输入用户名。当它被卡住时,我在控制台上的消息

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'

用来较早工作的相同代码。我正在使用Python 2.7.12和最新版本的Chrome Driver。

另外

注意:相同的代码工作较早,但是现在它不起作用

您是否尝试过

driver.switchTo().alert();

driver.switchTo().activeElement();

键入凭据?

但是,如果这起作用,我无法解释为什么它以前起作用。

尝试自动创建一个用于Windows身份验证的EXE,并在需要的情况下(如果没有其他工作(将其调用。如果您主要与Pyton合作,请尝试此

示例代码: -

WinWaitActive("Authentication Required","","120")
If WinExists("Authentication Required") Then
Send("username{TAB}")
Send("password{Enter}")
EndIf

您可以尝试直接自动化键盘?它可能起作用。您将键盘自动化。

在这里回答了一个类似的问题-https://stackoverflow.com/a/49109132/6003362

最新更新