Selenium webdriver not invoking .exe file generated by AutoIT files

2,897 views
Skip to first unread message

ravi

unread,
Aug 31, 2012, 6:19:34 AM8/31/12
to seleniu...@googlegroups.com
Hi,

I am trying to automate downloading a file in IE 9 using Selenium webdriver. Since Selenium doesn't handle OS pop ups or windows I had to use a third party tool AutoIT to get the work done.
Referred this site to start. Created a .au3 file which saves the file once the File download bar appears at the bottom of the IE window. Here is the script for .au3 file : 
SaveExcel.au3 : 
$hIE = WinGetHandle("[Class:IEFrame]")

$hCtrl = ControlGetHandle($hIE,"","[Class:DirectUIHWND]")
$aPos = ControlGetPos($hIE,"",$hCtrl)
$x = $aPos[2]-160
$y = $aPos[3]-30
Use
;WinActivate($hIE) ;doesn't work in the background
;ControlClick($hIE,"",$hCtrl,"primary",1,$x,$y) ;this only gives focus to the save button
;ControlSend($hIE,"",$hCtrl,"{Enter}") ;this does work once the save button is focussed

;Or alternatively:
$x += $aPos[0]
$y += $aPos[1]
WinActivate($hIE)
MouseClick("primary", $x, $y, 1, 0)


Am using Junit to automate the web app. Here is the code which runs in Junit file :

 Option 1: Process proc = Runtime.getRuntime().exec("D:\\AutoIT\\SaveExcel.exe"); ----dint work. Selenium is not able to invoke this .exe file which is generated after compiling .au3 file
Option 2 : Runtime rt = Runtime.getRuntime(); 
Thread.sleep(1000);
Process proc=rt.exec(new String[]{"cmd.exe","/c", "C:\\Users\\u0160720\\Desktop\\saveexcel.bat"});-----------dint work. The saveexcel.bat contains the steps to execute .au3 file in command line
Thread.sleep(1000);
int exitCode=proc.waitFor();
Thread.sleep(1000);

The thing to note here is if I run the any one of the above code in a junit file without any selenium code in it, it works. But if the junit file contains the selenium code and the code mentioned above, its not working. 
My question here to ask is what's stopping selenium to invoke this process in which it has to run a .exe file generated by AutoIT ?? 
If I use notpead.exe in the Process to run, it works. 

Any help is greatly appreciated. 

Peter Gale

unread,
Aug 31, 2012, 6:47:02 AM8/31/12
to Selenium Users
http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/


Date: Fri, 31 Aug 2012 03:19:34 -0700
From: ravi...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Selenium webdriver not invoking .exe file generated by AutoIT files
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/1wI4dWOi33QJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ravi

unread,
Sep 3, 2012, 11:06:49 AM9/3/12
to seleniu...@googlegroups.com
Thanks, Peter. After a prolonged R&D I came to conclusion that Selenium WebDriver doesn't support invoking AutoIT exe files when it comes to download files from a web browser. The browser hangs when trying to invoke .exe files created by AutoIT. May be a bug in WebDriver. 
Now I have to rely on either Java Robot classes or the FileDownloader java class which you have mentioned. 



Thanks
Ravi.

ravi

unread,
Sep 3, 2012, 11:16:36 AM9/3/12
to seleniu...@googlegroups.com
Tried using the FileDownloader class . 

Getting the error : cannot convert from element type Object to Coockie at the mentioned line.

 private BasicCookieStore mimicCookieState(Set seleniumCookieSet) {
        BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
        for (Cookie seleniumCookie : seleniumCookieSet) {------------------------------------------->>error
            BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
            duplicateCookie.setDomain(seleniumCookie.getDomain());
            duplicateCookie.setSecure(seleniumCookie.isSecure());
            duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
            duplicateCookie.setPath(seleniumCookie.getPath());
            mimicWebDriverCookieStore.addCookie(duplicateCookie);
        }
 
        return mimicWebDriverCookieStore;
    }

Please help.
-----------------------------

Peter Gale

unread,
Sep 3, 2012, 1:20:15 PM9/3/12
to Selenium Users
I have successfully invoked AutoIT .exe files myself before from Selenium.

After you have called the AutoIt .exe file, it is no longer anything to do with Selenium, it is an AutoIT issue,



Date: Mon, 3 Sep 2012 08:06:49 -0700
From: ravi...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Selenium webdriver not invoking .exe file generated by AutoIT files
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/dRScny64WNIJ.

PeterJef...@hotmail.co.uk

unread,
Sep 3, 2012, 1:40:56 PM9/3/12
to seleniu...@googlegroups.com
Not sure ... have you got all the import statements copied into your class?

ravi

unread,
Sep 4, 2012, 1:30:36 AM9/4/12
to seleniu...@googlegroups.com
Yes. Following are the imports. And i have created a test too as mentioned in the link you have sent, but first I need to get this class working in order to use it.

import org.apache.commons.io.FileUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.log4j.Logger;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
 
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Set;

Mark Collin

unread,
Sep 4, 2012, 1:37:26 AM9/4/12
to seleniu...@googlegroups.com

First thing to do is check the versions of commons-io and httpclient are correct (they are quite a bit different from older versions and possibly different from newer versions if they have come out since that was written)

 

https://github.com/Ardesco/Powder-Monkey/blob/master/pom.xml

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/zgvmlFiEz34J.

ravi

unread,
Sep 4, 2012, 3:44:56 AM9/4/12
to seleniu...@googlegroups.com
Hi Peter, following is my scenario which I am trying to automate using Selenium WebDriver and Junit

I am trying to download an  Excelfile from IE 8. When the dialog box opens up, I just need to click on Open, confirm whether the excel file is opened and then close the Excel file. Fore this I have tried a lot using AutoIT scripts. The thing is am trying to invoke the AutoIt exe file from a Junit file which has Selenium Webdriver code as well. Once the Selenium is done with its job till coming upto Download link, the autoIt exe file should invoke in order to handle the File Download dialog box, using RunTime.getRuntime.exec(String command), where the command is path to the AutoIT exe file. Let me know if you have some solution to this. What I can say is I ve a hard time trying to get it worked from my Junit file, which has Selenium WebDriver code as well. If I invoke any other exe file from my Junit file , such as notepad.exe, it works fine. So am thinking Selenium WebDriver is not able to invoke my AutoIT exe files. Any help is greatly appreciated. 

Regards
Ravi

Peter Gale

unread,
Sep 4, 2012, 4:00:36 AM9/4/12
to Selenium Users
An exe is an exe. I'm sure there is nothing in WebDriver or jUnit that will stop your AutoIT script working, however, you are better off working with the pure java solution that Mark is best placed to help you with.


Date: Tue, 4 Sep 2012 00:44:56 -0700
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/PBBipnggXvgJ.

ravi

unread,
Sep 4, 2012, 4:53:54 AM9/4/12
to seleniu...@googlegroups.com
Thanks Pete, I will try with that.

jeevan

unread,
Sep 4, 2012, 7:13:52 AM9/4/12
to seleniu...@googlegroups.com
 If I invoke any other exe file from my Junit file , such as notepad.exe, it works fine. So am thinking Selenium WebDriver is not able to invoke my AutoIT exe files. Any help is greatly appreciated. 

The above statement is confusing.. have you tried opening notepad.exe with WebDriver? If so then have to check your AutoIt exe file.

Thanks,
Jeevan.


To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/h3VsU3G00QkJ.

Anji Prassana

unread,
Sep 4, 2012, 7:46:19 AM9/4/12
to seleniu...@googlegroups.com
Have you tried invoking your Autoit script [SaveExcel.exe] manually and are you sure that it's working?? If it works manually then it should work when you call through java Runtime as well.
 
Also,
you started your script directly with the assumption that widow already exists and you are getting this handle as shown below...
  $hIE = WinGetHandle("[Class:IEFrame]")
So, try to put winwait() and winwaitactive() related functions prior to the above line in Autoit script. So that, it will wait till the window come up and will active..
Thanks&Regards
Anjaneyulu P
"The way you see the things is the way to think and is the way you react upon!!"

jeevan

unread,
Sep 4, 2012, 8:05:37 AM9/4/12
to seleniu...@googlegroups.com
Hope it's  not good to discuss AutoIt issues here, you have to modify the SaveExcel.exe file....There were some changes need to do.

Thanks,
jeevan

Peter Gale

unread,
Sep 4, 2012, 8:18:57 AM9/4/12
to Selenium Users
We ought to stick to Selenium issues only, really, and we have given ravi a lead on a more Selenium related approach (at least in as much as it is a compatible class "donated" by a keen Selenium supporter), so if anyone want to help Ravi with the details of getting his AutoIT script working, can I suggest they talk to him direct (i.e offline)  about it?

Thanks
Peter


From: g1re...@gmail.com
Date: Tue, 4 Sep 2012 17:35:37 +0530

Subject: Re: [selenium-users] Selenium webdriver not invoking .exe file generated by AutoIT files

ravindra.k

unread,
Sep 4, 2012, 8:30:30 AM9/4/12
to seleniu...@googlegroups.com
Agree with Jeevan. I have mentioned in my last post I will go for java solution given by Mark. Anyways, thank you all for the support. 
Regards,
Ravindra K

Amit

unread,
Sep 6, 2012, 2:43:15 AM9/6/12
to seleniu...@googlegroups.com
I am using following autoscript to save the downloaded xls file  and it works for me. try this out:

WinWait("[Class:MozillaDialogClass]")
WinActivate("[Class:MozillaDialogClass]","")
Send("!s");
Send("{ENTER}")


Thanks
-Amit

Amit

unread,
Sep 6, 2012, 2:44:36 AM9/6/12
to seleniu...@googlegroups.com
I am using this on FF.
Message has been deleted

SK

unread,
Aug 29, 2014, 1:16:43 AM8/29/14
to seleniu...@googlegroups.com

Selenium 2.42.2 is not wotking to invoke .exe like for AutoIt


I want to upload a photo by selenium webdriver.
I used following environment:
[Selenium 2.42.2]
TestNg,
Firefox 26to 30,
[AutoIt][2]

Here is Test.java code

   
driver.findElement(By.id("photo")).click();
Runtime.getRuntime().exec("Z://browseExample.exe");

but selenium doesnot run the line to execute automatically.
If I manually clicks on “browseExample.exe” then it writes the desired path in browse textbox and clicks on open.

I noticed that, with selenium jar like 2.39, 2,38 it works fine.

But with those jars, my application’s one locator of password field is not working.
When password is entered it displays in plain text and even clicking on submit button, it doesn’t accepts that password

here is html of password field

   
<div class="formbox">
 
<input type="password" value="Password" onclick="this.value == 'Password' ? this.value = '' : this.value;" onfocus="this.select()" onblur="javascript:return ShowDefaultText();" maxlength="255" title="Please enter password" name="textBoxPassword" tabindex="2" id="textBoxPassword" style="display: none;">
 
<input value="Password" onclick="this.value == 'Password' ? this.value = '' : this.value;" onfocus="javascript:return HideDefaultText();" maxlength="255" title="Please enter password" tabindex="2" name="textBoxPasswordRegular" class="logintext" id="textBoxPasswordRegular" style="display: block;">
 
</div>

Here is AutoIT code of  browseExample.exe

   
; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set input focus to the edit control of Upload window using the handle returned by WinWait
ControlFocus("File Upload","","Edit1")
Sleep(2000)
; Set the File name text on the Edit field
ControlSetText("File Upload", "", "Edit1", "Z:\snipett.txt")
Sleep(2000)
; Click on the Open button
ControlClick("File Upload", "","Button1");

sekha...@gmail.com

unread,
Oct 25, 2015, 11:18:16 PM10/25/15
to Selenium Users
Thanks Ravi its true selenium older version not supporting AutoIT.

David

unread,
Oct 27, 2015, 1:54:48 AM10/27/15
to Selenium Users
If I'm not mistaken, I noticed the OP did not post the relevant code where the file download link action occurs and where AutoIt is executed relative to that.

I would like to point out that certain Selenium commands (or their resulting actions) are (UI) "blocking". And the result of clicking a link that brings up a save file dialog (if browser not set to auto-save/download) may likely be blocking, meaning it can cause Selenium to hang if you do nothing (manually) to handle the file save popup after the click command. That means the (Java) code is stuck at the line/command that does the click that brings up the dialog, so it can not execute the next command which is typically the one to run AutoIt executable. If that is the case, you will need to launch AutoIt before clicking the link that causes the download. Modify the AutoIt code to "wait" for the save file dialog window to appear before handling it, for it to synchronize with the Selenium click action.

Also, if going the file download route in native Java (link from Peter), and having issues with that sample code, here's a simpler version one can try: https://gist.github.com/daluu/4411221
Reply all
Reply to author
Forward
0 new messages