Windows Security User Login In Selenium With AutoItX.Dotnet In C#

Last week, I worked on Selenium; not for testing purposes, but for automating a workflow in my project. To automate that workflow, I had to cross a big hurdle - a Windows Authentication popup in between the workflow. I tried everything like appending URL with credentials but nothing worked. At the end, I got to know about autoitx.dotnet NuGet application.

Problem statement

How to authenticate Windows user login when working on Selenium.

 

Solution

  1. I am assuming you already have a running project with Selenium.
  2. Now, go to the NuGet gallery and search for “Autoit” NuGet.



  3. Install the above NuGet package.
  4. Now, add the below code where you want to authenticate Windows User Login.
    1. IWebDriver driver = new InternetExplorerDriver();  
    2. driver.Navigate().GoToUrl("http://localhost/Home/StephenSecrets");  
    3. //Thread.Sleep(500); //if required  
    4. AutoItX.WinWaitActive("Windows Security");  
    5. AutoItX.ControlSetText("Windows Security""""Edit1""TestUser"); //replace testuser with actual username (with domain if required)  
    6. AutoItX.ControlSetText("Windows Security""""Edit2""Password_test"); //replace Password_test with actual Password  
    7. AutoItX.Send("{ENTER}");  
  5. It’s done.
  6. You can find this sample project on my GitHub repo.
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now