I'm using the "native" C# SendKeys, as well as the AutoItX library, in C# (VS 2015) to manually enter login credentials into a login window on a Windows 10 computer.
For a long time, this has been working flawlessly. Then, apparently all of a sudden - with no changes done on my part - a delay of more than 1 minute is dominating all my code samples. That is - SendKeys.SendWait()
and the Send()
method of AutoItX both work, but it takes more than a minute to send the keys to the active window.
Here's my code:
I'm using Selenium WebDriver to open a Chrome browser window, and SendKeys.SendWait()
or AutoItX.Send()
to send the username and password, as well as TAB and ENTER to the login window.
public void OpenAndLoginSelenium (string username, string password) {
// Create the Selenium instance and navigate to the page:
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
Instance = new ChromeDriver(driverService);
Instance.Navigate().GoToUrl("http://my-lab-drop2.telecomputing.com");
// Alternative 1 - using AutoItX:
AutoItX.WinActivate("Authentication required", "");
AutoItX.Send(username);
AutoItX.Send("{TAB}");
AutoItX.Send(password);
AutoItX.Send("{TAB}");
AutoItX.Send("{ENTER}");
// Alternative 2 - using SendKeys():
SendKeys.SendWait(username);
SendKeys.SendWait("{TAB}");
SendKeys.SendWait(password);
SendKeys.SendWait("{ENTER}");
}
Both alternatives work, but it takes 1 minute and 3 seconds (this delay seems to be pretty constant) before the first Send is executed. Nothing happens before this time has passed. There is no delay between the sends, however; As soon as the username string (in this example) is entered into the username field, the rest (TAB - enter password - ENTER) is executed quickly. Windows just waits one minute and three seconds before doing anything.
The login box is the standard systems login box created when Chrome enters a web page that requires authentication. I'm not able to post a link to the page, since it's an internal one, but please trust me on this. (Authenticating directly, using http://login:pass@url is not an option, since the process after entering the username/password involved a more complicated process than standard htauth, using som tokens and whatnot.)
There were no VISIBLE changes to the system between this working normally one afternoon and this delay suddenly being there the next morning, after a reboot of the system. I couldn't even find any log entries about any Windows updates or any other changes. But something has obviously happened - I'm just unable to find out what, and why this extreme and constant delay has come into effect.
UPDATE: The main question here is/was: Why is SendKeys() and AutoItX.Send() no longer working. The next question is: If there's no solution for this, what's the easiest alternative? What I need to do is type username and password into the login prompt of a browser (which is opened and further controlled by Selenium WebDriver) and log in to the web site. And enter text into and click buttons in things like file upload dialogs etc.