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

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.

48 thoughts on “How to Handle Window based Pop up using Selenium and AutoIT?

  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”)

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

    • 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.


      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

    If WinExists(“[CLASS:MozillaDialogClass]”) Then

  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:

    package tests;


    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();




    WinWaitActive(“Authentication Required”,””,”10″)
    If WinExists(“Authentication Required”) Then

    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.

  8. Hi sudeep,

    I need some help in here.
    My task is : I have to click a link on Firefox so download dialog box(window popup not browser) will appear and than i have to open file(file is txt so will open in notepad). Now i have to assert that file has some particular line in it. While doing this My Selenium script should wait for the result, or may take input from autoit about that line. If that line is present script should move forward else should fail.

    I am have automated upto opening my file in notepad but problem is how to get some return value from autoit and how to wait in selenium till that value comes.

    Can you please help me with this.

    • There is a suggestion for this problem. You can do just till the download part using AutoIT. Once the file is added just write a file reading code to do the read instead of using AutoIT to do so. It will implicitly wait till the execution of read code is over. If you use java you can use IO under utils.

  9. Thanks a lot Sudeep,
    Yeah that really helped. But there is 1 more thing than, how can we know if autoscript run is successful or failed, I mean when we call autoscript to save/open that file auto it will just run and open/save it. But how do we find that if file even get downloaded or not. May file didnt even got download and autoit gets failed.

    i use Process p = Runtime.getRuntime().exec( processName ); to execute the script but how will i know if it gets downloaded or not.

      • Actually, we can’t use sendKeys here because save dailouge box is window popup and not browser popup. So we can’t find the element using driver.findElements. I even checked it by Selenium IDE.
        So we needs to use some window automation tool like autoit there. But than problem is, when i calls my autoit script, it start running parallel to my selenium script. Selenium script doesn’t wait for it to complete and don’t even know if Autoit script gets passed or not.

  10. Hi Sudeep,

    I am using AutoIt script for a pop up in Watir-Webdriver. But when I run the watir script I am getting “uninitialized constant Runtime (NameError)”.

    Need help in this.

    Below is the code:

    I am executing the scripts from a linux server. When the user clicks on the “Calc” link in the page, the calculator opens in the remote windows desktop during which it asks for a user name and password for authentication.

    require ‘watir-webdriver’
    require ‘d:\\Ruby\\page_object_sgd_3’
    require ‘d:\\Ruby\\sgd_linux_3_Log_In’
    require ‘au3’


    puts ” ”
    puts ” ”
    puts “=======TestCase 3.1: Clicking on the ‘Calc’ option=======”

    sleep 10


    AutoIT code:

    WinWaitActive(“Authentication for”, “”, “20”)
    If WinExists(“Authentication for”)Then

  11. Hi Sudeep,

    Sorry, I got the answer.. Instead of doing this “Runtime.getRuntime().exec(“D:\\Ruby\\authentication.exe”)”, we need to run it as a system command or using back tick (“).

  12. Hello all,
    I stumbled upon this post while searching for Autoit script to be used for IE proxy authentication as IE behaves entirely different than ff and chrome.

    After doing a short study on the Autoit Functions I was able to write a script of my own.
    Sharing the same for reference.

    if WinWaitActive(“Connect to {name of your proxy/ip}”)Then
    Beep(500, 1000)
    ControlSetText(“Title” , “Identifier_text”,”Edit2″,$UN)
    ControlSetText(“Title” , “Identifier_text”,”Edit3″,$PWD)
    Sleep (500)
    Sleep (10000)


    -Raj Sarodaya.

  13. Using Auto it not able to handle browser pop up window in firefox.Here is the code

    package mypackage;

    import java.awt.Robot;
    import java.awt.event.KeyEvent;
    import org.testng.annotations.*;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import com.thoughtworks.selenium.DefaultSelenium;
    import com.thoughtworks.selenium.Selenium;
    import Data.Function;

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

    public class Report extends Function{

    Object Open_a_popup_window ;
    String Positioned_Popup ;
    Object JavaScript_Popup_Windows ;
    private Selenium selenium;

    public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = ” “;

    public void inventory() throws Exception {
    Function object = new Function();
    Runtime.getRuntime().exec(“C:\\Program Files (x86)\\AutoIt3\\Examples\\Authentication.exe”);
    /*Enter Report Details */

    driver.get(baseUrl + “/dashboard/dashboard”);
    driver.get(baseUrl + “/report/”);


    WebElement Action = driver.findElement(By.xpath(“.//*[@id=’tableListingData’]/div/div”));

    String linktxt = Action.getText();

    if( linktxt.equalsIgnoreCase(“Record not found.”))

    System.out.println(“Report_US contains No Data:”);



    System.out.println(“Report_US failed”);
    else {


    //After this line if CSV file present browser window pop up opens. So guide me how to handle it.
    public void teardown() {
    If WinExists(“[CLASS:MozillaDialogClass]“) Then

  14. Hi, I am a Selenium and Ruby newbie. Can anyone help? What would the code look like in AutoIT (to run from Selenium with Ruby if I wanted to act on the IE brower Save Dialog. Specifically, to click on save, then save the file to a particular location?

  15. What AutoIT does that SendKeys does not?

    consider a scenario to upload a file. I am able to use autoIt script as well as sendkeys to upload a file.
    -> driver.findElement(By.xpath(“input field”)).sendKeys(“path of the file which u want to upload”);

    By using above single line I am able to upload a file,then why i should use Autoit script?

  16. hi,
    I have tried Runtime.getRuntime().exec(“C:\\Users\\Desktop\\pop.au3.exe”); but value is not passing to the popup window. autoIT script used by me is given below-
    WinWaitActive(“Authentication Required”,””,”10″)
    If WinExists(“Authentication Required”) Then

  17. Hi,

    I am using auto IT .exe file before clicking on an element. It is handling the pop up window but code gets stuck on .click() method and does not run further.
    Any Suggestions?

  18. I am using autiIT .exe file before clicking on an element. The pop up is getting handled successfully but the code gets stuck on click method and doesnt run further.
    Any suggeations?

  19. Hi sudeep i was a beginner for selenium and i have successfully handled the Auth window pop up for the first time, unfortunately my scenario was the same Auth window will pops up at 2-3 times in my application so that i have copied the same Runtime code and paste it wherever it ask but as bcz of the exe file already opened and not closed it was not providing the Authentication for the second time suggest me i how to handle the Auth window when ever pops up and after completing i have end the process of the .exe

    when the code was not taken into the application i have checked in background process it was running pls suggest how to close it

  20. Hi,

    what we need to do if i’m getting this authentication more than 2 times while running my script.

  21. Hi Sudeep,
    I use mac and so cannot use autoIT. I get an authentication window to access my testing site.
    I could successfully authenticate the site but the authentication window does not close after that.
    Below is my code

    driver.get(“”); // main site opens
    try {
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block

    driver.get(“”); // accepts the username and password in authentication //window and the site opens


    //But the window remains open and doesnot close after

  22. Hi Sudeep,

    Need help on excel window popup, i want to action this window by autoit, can you suggest me some code

  23. Cool. Using AutoIt like this by creating the exe and running it to handle the popups is really cool. However, can we not do the same using JACOB Jar package that use the AutoIt inside but gives APIs to work with popups. Also it’s better to provide the path using a configuration file instead of hard wiring it directly in the Runtime.getRuntime().exec().

  24. Hi Im using Auotit fro Chrome and it sends user name and password and hits enter
    but gain it comes back with same authenitication site instead of landing page

    WinWait(“ – Google Chrome”,””,”60″) ; this is the name of the window, according to AUTOIT v3 window info WinActivate(“ – Google Chrome”) ; set control to the window for proxy authentication Send(“pradeep.rajacXXX{TAB}”) ; send username and press TAB Send(“XXXXX{ENTER}”) ; send the password and press enterj

    System.out.println(“Inside testInspire “);

    baseUrl = “”;

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);




  25. hi
    I m using AutoIt script to handle authentication popup.
    It works fine for firefox but for chrome when the popup appears after that nothing is executed.

  26. Hi Sudeep, i have a scenario where we are creating a policy and performing some activity which turns on block pop up on the browser and doesnt allow to perform any other operation until unless we handle the block pop up. earlier it was working with AutoIT but with upgrade to selenium 3.0 it is not working in chrome as well as in firefox. Can you pls help me out.

Leave a Reply

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

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

Facebook photo

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

Connecting to %s