Tuesday 4 June 2013

Windows authentication login using Selenium

Handling Javascript windows with selenium is not much of a problem since selenium has an inbuilt driver to it.But the problem with websites that use windows authentication is that they are neither Javascript popups nor they can be controlled by Java AWT Robot individually.

To overcome the trickyness, we use selenium to first recognize the pop up as as Javascript pop-up and then use Java AWT Robot to enter the password.

Why use Java AWT?
Well selenium by itself cannot handle this situation.It can enter the username but cannot make a tab switch and enter the password.

Below is an image of the login ( Windows authentication ) using ASP.NET

















Github link to the code : 

https://github.com/Madusudanan/Selenium/blob/master/WindowsAuthHandler.java

It can also be used to handle windows of similar nature that pops up out of a browser.Usually these kinds are associated with Domain/Active directory authentication.

Code is commented for understanding.Let me know in case of any doubts or issues that you face.

Edit : As of September 26 , the above piece of code works only with Internet Explorer Driver. For other browsers we have to resort to libraries such Auto IT or Sikuli