How to Handle Window based Pop up using Selenium and AutoIT?

Some times while doing testing with selenium, we get stuck by some interruptions like a window based pop up.  I have faced similar situation while doing my analysis. Since we were using a proxy to connect to internet, any page we open will ask for proxy authentication in a window based pop up. But selenium fails to handle this as it has support for only web based application. To overcome this problem we need to use AutoIT along with selenium script. AutoIT is a third party tool to handle window based applications. The scripting language used is VBScript.

So let’s take the example of the problem I was facing. Every time you open a page you get a pop up asking for authentication. To overcome the problem let create an AutoIT script first. To do so let’s create one file with any name and .au3 extension in any location. Let’s say the file name is Authentication.au3 and it’s created in the example folder of the AutoIT installation folder. So we need to know the window title of the window that is disturbing our test. Taking an example of Firefox let’s consider the window title as “Authentication Required”. The script to handle this pop up is as below which is written inside Authentication.au3. You need to write click on the file and click edit and write the following.

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

Now save the file and click on tools and compile it. One more file with same name but with .exe extension will be created in the same location. This file needs to be used inside selenium script. How to use it. It’s pretty simple. We need to add one statement in the setUp method before calling the recursive setUp method with the URL. Below is the statement that needs to be added.

Runtime.getRuntime().exec("C:\\Program Files\\AutoIt3\\Examples\\authenticationFF.exe");

The whole path along with the file name has to be passed to exec method. Now when you fire your script your autoIT script will be fired first and the initial pop up will be handled.

About these ads

18 Comments

  1. This didn’t really work for me… so I used the following:

    WinWaitActive(“Windows Security”)
    ControlSetText(“Windows Security”,”",”Edit1″,”user”)
    ControlSetText(“Windows Security”,”",”Edit2″,”pass”)
    Send(“{ENTER}”);

  2. WinWaitActive(“Windows Security”)
    ControlSetText(“Windows Security”,”",”Edit1″,”user”)
    ControlSetText(“Windows Security”,”",”Edit2″,”pass”)
    ;Click Ok/Login button
    Send(“{ENTER}”);

    • Generate the exe using autoIT. Then use the following command where you want the exe to be executed.

      Runtime.getRuntime().exec(“C:\\Program Files\\AutoIt3\\Examples\\.exe”);

  3. Hi Thanks a lot for making us handling the pop-ups easier.but I am facing problem in handling the
    new window generated by the pop-up window.

    Here is the scenario When we click “OK” on the pop-up window a new window that is the excel file needs to get opened And we need to focus on that window ,after that we need to change the focus back to the main window

    • Hi Chethana,

      You can WinWait for the same. Below is an example for a notepad file.

      Run(“notepad.exe”)
      WinWait(“[CLASS:Notepad]“)

      You need to find out what the classname should be for the xls file. This will solve your problem.

  4. Hi Sudeep,

    Here is the code that i have used to handle a window pop-up.It works fine only after I click on the window

    WinWaitActive(“[CLASS:MozillaDialogClass]“,”",10)
    If WinExists(“[CLASS:MozillaDialogClass]“) Then
    Send(“OK{ENTER}”)
    EndIf

  5. Hi can we handle SSL certificates in google chrome using selenium ? if not what else can be done for the same. Your help will be highly appretiated.

  6. Hello blogger,

    My webdriver code is not running the AutoIT exe file. However if I open the website and run the AutoIT exe file separately, it works.

    Also, I could find in some site that says, AutoIT is not supported in Webdriver.

    Is there any workaround?

    Here is my code:

    SeleniumTest.java

    package tests;

    import java.io.IOException;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class Handling_Windows_Based_Prompt {

    public static void main(String[] args) throws IOException{
    WebDriver c1 = new FirefoxDriver();
    c1.get(“http://my.test..in”);
    Runtime.getRuntime().exec(“E:\\authenticationFF.exe”);

    }

    }

    authenticationFF.au3

    WinWaitActive(“Authentication Required”,”",”10″)
    If WinExists(“Authentication Required”) Then
    Send(“CHENNAI/sumand{TAB}”)
    Send(“smartek@1212{ENTER}”)
    EndIf

    Kindly reply

  7. Hi,
    My problem is after entering wrong username and password,one pop up is coming which is giving message “invalid Username And Password” and one ok button is there .If i click on that ok button then again it will go to login page.but i am unable 2 handle that pop up box.That pop up box has no title.Please help me how will i solve my problem.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s