Header Ads

How to handle Windows Security Pop-Up Window In Different Browsers

Handling JavaScript popup using selenium webdriver is relatively easy. But handling of a pop up becomes tough if the browser uses windows authentication dialog box. Well, how the windows authentication looks like-I have given them below:
Windows Authentication
It will not have anything.I mean you can not really inspect them using firebug or inspector. Mostly if an underlying application uses windows authentication, It will look like this through Mozilla or Internet Explorer browser. Most importantly this is modal dialog box. Hence we can not avoid this. Now Webdriver supports browser level identification not windows level. So net on net we can not automate this using selenium.

By the time selenium comes with some solution let me write all possible way i tried..
Before I go deep into this let us understand different pop ups available in an application. They are as follows:

1. HTML pop-up
2. JavaScrip pop-up
3. Win32 pop-up
4. Modal pop-up
5. File upload pop-up
6. File download pop-up  

For more details please visit this blog

So HTML pop-up and JavaScrip pop-up can be handled by Selenium itself. Problem starts third points on words.
Initial days I tried with robot class as all most all the forum talked about this solution. i.e Robot class.
Robot robot  = new Robot();

but it is not working flawlessly. I tried By adding user id and password before start of url<
But quickly I understand that this is a security issue. No browser will support that for long.As a result this was not my code to work with security popup.
Then one fine morning I found out a stack overflow thread. That was indicating some tool called AutoIT. The tool seemed to be very user friendly and easy to use.The code looks like-
WinWaitActive("","Authentication Required","120")
 If WinExists("","Authentication Required") Then
After creating this code I had to save this as an executable file like authentication.exe. Then used the below code to execute the executable file.
or one more solution was-
WinWaitActive(“Windows Security”)
ControlSetText(“Windows Security”,””,”Edit1″,”user”)
ControlSetText(“Windows Security”,””,”Edit2″,”pass”)
//Click Ok/Login button
Problem solved!! I was very happy to use this solution. It was running nice for Internet Explorer and Firefox browser. But when I thought everything was over , Chrome came up with unique problem.
The same popup came in a form based authentication form.

something like the image. Most importantly this was modal dialog box.This was appearing as an extra security after giving user name and password and click on sign in.Since this was modal dialog box WebDriver click control was getting trapped inside. It was  not executing next statement.
So if the browser was chrome it was not possible to switch to alert and put all values. AutoIT failed to identify the alert itself. To add more pain this authentication may come 2-3 times even more than that.
So I had to find some other solution.
I found sikuli then,a free image based little week but steady solution.
Process was very simple.Added the sekuli jar to the classpath.
I created the images as per sikuli editor.

And the sample prototype code was-
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.sikuli.script.*;

public class ChromePrototype {

 public static void main(String[] args) throws InterruptedException, IOException, FindFailed {
  // TODO Auto-generated method stub
   System.setProperty("webdriver.chrome.driver", "D:\\SeleniumT\\ChromePrototype\\chromedriver.exe");
  WebDriver driver ;

  ChromeOptions options = new ChromeOptions();
  driver = new ChromeDriver( options );
   Pattern floginButton = new Pattern("D:\\imagebase\\fLogin.png");
   Screen screen = new Screen();

   Pattern userName = new Pattern("D:\\imagebase\\UserName.png");
   Pattern authentication = new Pattern("D:\\imagebase\\Authenticati.png");
   while(screen.exists(authentication) != null);

 public static void  LogIn() throws FindFailed, InterruptedException
   Screen screen1 = new Screen();
   Pattern userName = new Pattern("D:\\imagebase\\UserName.png");
  // screen.wait(userName, 10);
   Pattern password = new Pattern("D:\\imagebase\\Password-1.png");
  // screen.wait(password, 10);
   Pattern secondlogin = new Pattern("D:\\imagebase\\secondlogin.png");


It worked. Since the first click is originated from sikuli so webdriver click trapping was resolved.I will update this page if I get better solution But till then. Sikuli did my job!!!.

Powered by Blogger.