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.
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}”);
WinWaitActive(“Windows Security”)
ControlSetText(“Windows Security”,””,”Edit1″,”user”)
ControlSetText(“Windows Security”,””,”Edit2″,”pass”)
;Click Ok/Login button
Send(“{ENTER}”);
Hi Wulfgar,
Where do we need to put this code in selenium script?
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”);
Pisso ekka AutiIT usage eka
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,
Does it open a browser window or any other file? Depending on the type the solution will vary
Hi Suddep,
It opens the Read only Microsft Excel file with the .xls extension
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.
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
Instead of using WinWaitActive, you can use just WinWait. That will solve the problem.
It was not working for me. I was tried many possiblity.
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.
U can achieve the same using autoIT. Use you browser window name to find the window. Then perform the certificate accept sequence. That should solve your problem.
U can achieve the same using autoIT. Use you browser window name to find the window. Then perform the certificate accept sequence. That should solve your problem. Use the appropriate functions available at below mentioned link.
http://www.autoitscript.com/autoit3/docs/functions.htm
hi,
yes we can handle SSL Certificates by using “desired capabilities” class for chrome,IE browsers
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
May be you need to increase the timeout from 10 to some larger value and give it a go.
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.
is it a pop up or alert?
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.
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.
If you are using you can use sendKeys instead of autoIT
Example:
driver.findElements(By.id(xyz)).sendKeys(Keys.ENTER);
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.
Its now working in chrome. Any suggestion is highly appreciated
it is independent of browser. it can be a timing issue
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’
begin
puts ” ”
puts ” ”
puts “=======TestCase 3.1: Clicking on the ‘Calc’ option=======”
click_calc
@frame_calc.click
sleep 10
Runtime.getRuntime().exec(“D:\\Ruby\\authentication.exe”)
AutoIT code:
WinWaitActive(“Authentication for host21.uk.xxxxxx.com”, “”, “20”)
If WinExists(“Authentication for host21.uk.xxxxxx.com”)Then
Send(“xxxx{TAB}”)
Send(“xxx{Enter}”)
EndIf
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 (“).
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.
;*****************************************************************************************************************
AutoItSetOption(“WinTitleMatchMode”,”1″)
if WinWaitActive(“Connect to {name of your proxy/ip}”)Then
Beep(500, 1000)
$UN=(“Username”)
$PWD=(“Password”)
Sleep(500)
ControlSetText(“Title” , “Identifier_text”,”Edit2″,$UN)
Sleep(500)
ControlSetText(“Title” , “Identifier_text”,”Edit3″,$PWD)
Sleep (500)
Send(“{TAB}”)
Sleep(100)
Send(“{Enter}”)
Sleep (10000)
Run(“Authenticate-IE.exe”)
EndIf
;*****************************************************************************************************************
Regards,
-Raj Sarodaya.
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;
//import org.openqa.selenium.support.ui.Select;
public class Report extends Function{
Object Open_a_popup_window ;
String Positioned_Popup ;
Object JavaScript_Popup_Windows ;
private Selenium selenium;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = ” “;
}
@Test
public void inventory() throws Exception {
Function object = new Function();
object.Login();
Runtime.getRuntime().exec(“C:\\Program Files (x86)\\AutoIt3\\Examples\\Authentication.exe”);
/*Enter Report Details */
driver.get(baseUrl + “/dashboard/dashboard”);
driver.get(baseUrl + “/report/”);
/*Run*/
driver.findElement(By.xpath(“.//*[@id=’productFiltersRight’]/div[1]/input”)).click();
Thread.sleep(80000);
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:”);
}
if(linktxt.equalsIgnoreCase(“FAILED”))
{
System.out.println(“Report_US failed”);
}
}
else {
driver.findElement(By.xpath(“.//*[@id=’filters_advance_top’]/div[4]/a/img”)
//After this line if CSV file present browser window pop up opens. So guide me how to handle it.
}
@After
public void teardown() {
driver.close();
//System.exit(0);
}
}
Authentication.au3
WinWait(“[CLASS:MozillaDialogClass]“,””,10)
If WinExists(“[CLASS:MozillaDialogClass]“) Then
Send(“OK{ENTER}”)
EndIf
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?
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?
Great Thanks.. As i am very new to AutoIT, this code is really Helpful for me.
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
Send(“username{TAB}”)
Send(“pasword{Enter}”)
EndIf
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?
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?
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
Hi,
what we need to do if i’m getting this authentication more than 2 times while running my script.
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(“https://Site.com/”); // main site opens
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.switchTo().alert();
driver.get(“https://usenername:passwd@site.com”); // accepts the username and password in authentication //window and the site opens
}
//But the window remains open and doesnot close after
AutoIT will not work with mac. Will try to find an alternative and get back.
Hi Sudeep,
Need help on excel window popup, i want to action this window by autoit, can you suggest me some code
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().
I agree with you. This is very old post and the approach is outdated.
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(“https://inspire.spi.com – Google Chrome”,””,”60″) ; this is the name of the window, according to AUTOIT v3 window info WinActivate(“https://inspire.spi.com – 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 = “https://inspire.spi.com/”;
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(baseUrl);
Runtime.getRuntime().exec(“C:\\IPOD_Selenium\\WindowLoginAutoItCode.exe”);
Thread.sleep(5000);
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.
Hi Priya, this is a very old post. With current selenium version I would not recommend using AutoIt.
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.