How to Download file in IE browser using selenium webdriver ??

11,976 views
Skip to first unread message

SuRiNdEr Komire

unread,
Apr 18, 2016, 2:25:40 AM4/18/16
to Selenium Users
Hi All,

I want to down load a file from application and store in desired folder.
After that i want to read data from downloaded file and compare with existing other excel data.
Could you please anyone help writing script !!

SuRiNdEr kOmIrE

unread,
Apr 20, 2016, 4:51:52 AM4/20/16
to seleniu...@googlegroups.com
Could you please anyone help me in this matter.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/xw0xgJ0GhDI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ec3c34c5-d401-4ab7-b2f9-8dae27e1eaa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Surin Komire

Serguei Kouzmine

unread,
Apr 23, 2016, 9:34:44 PM4/23/16
to Selenium Users
Hello Komire

With IE, File download is a OS-native dialog. Direct automation of those is out of scope of Selenium itself, and is accomplished in different ways, dependent on what is your test suite codebase.  
For java, python or Ruby, autoit or sikuli is  used most often, for C# there are some projects automating the download dialogs  via p/invoked win32 calls.

Serguei Kouzmine 

SuRiNdEr kOmIrE

unread,
Apr 24, 2016, 3:22:07 AM4/24/16
to seleniu...@googlegroups.com
Hi Serguei Kouzmine,

Thanks for your kind reply. Using java i have designed framework. I know that downloading file using selenium is out of scope.
To download we need to use third party tools. But using AuotIT also im unable  download file.
Could yo please provide any alternative method. 
Please check the below scenario.

When i click on "Export To Excel" button, it will display below window which is not possible using selenium.



I want to click on Open/Save button and i want to get that file in specific folder.​


Please provide valuable suggestions.
Thanks in advance. :)
 ​



For more options, visit https://groups.google.com/d/optout.

pranab singh

unread,
Apr 24, 2016, 3:31:19 AM4/24/16
to seleniu...@googlegroups.com

Hi
  I   hope You are getting the open, save dialog using ie only. What happens if you use the same scenario in chrome.. I think it's downloaded just after clicking on export ri8.....
I faced the same issue in my application, when i run in my local machine its pass,but when i used the same code in German server, it fails.. Nor robot, nor autoit worked for me.so i tried downloading the file only using chrome.  After downloading i quit the chrome driver and continued the test using the same driver object,ie and Firefox

Regards

Pranab Chetri

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Nikhil Srivastava

unread,
Apr 24, 2016, 9:33:15 AM4/24/16
to seleniu...@googlegroups.com
Hi Surinder,

You can handle IE download popup using AutoIT.

As File download is a OS-native dialog in IE and Selenium can't interact with OS level popups so you need to handle it smartly.

You need to call AutoIT script even before clicking on "Export to Excel" link. 

Please follow below steps :-

1) Call AutoIT Script (Apply some wait in your AutoIT script, so your IE window handle script will start after clicking on Export to Excel )
2) Click on Export to Excel using Selenium

Let me know if you still facing any issues.

Thanks,
Nikhil

SuRiNdEr kOmIrE

unread,
Apr 25, 2016, 2:34:26 AM4/25/16
to seleniu...@googlegroups.com
Thanks pranab fr your kind reply.

Nikhil i didnt understand and unable to write script as you said.

I tried to find the open or save buttons using AutoIT tool but unfortunately without success. AutoIT detecting complete popup window as single window and there is no fifference when i try to find open or save button. Both having same element properties. For complete OS level popup its same/.and 'm unable to find elements using AutoIT tool so not able write script too.




Could you please explain in detail how to write script ??



For more options, visit https://groups.google.com/d/optout.

Nikhil Srivastava

unread,
Apr 25, 2016, 8:38:08 AM4/25/16
to seleniu...@googlegroups.com
Hi Surinder,

Please find Selenium and AutoIT Scrtipt below:-

Selenium Script:-

Process proc = Runtime.getRuntime().exec("C:\\AutoIT.exe");
   
driver.findElement(By.linkText("Export To Excel")).click();

Please be sure you need to call AutoIT Script before clicking on Export to Excel link.


AutoIT Script :-

;If you wait long enough then IE11 will automatically give focus to the Save As popup box
Sleep(5000)

Local $hIE = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")

If WinExists($hIE,"") Then
WinActivate($hIE,"")
ControlSend($hIE ,"",$hCtrl,"{F6}")          ; Gives focus to Open Button
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{TAB}")          ; Gives focus to Save Button
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{enter}")        ; Submit whatever control has focus
EndIf
Sleep(25000)

Hope it will help you.


Cheers,
Nikhil

SuRiNdEr kOmIrE

unread,
May 6, 2016, 3:50:36 AM5/6/16
to seleniu...@googlegroups.com
Hi Nikhil,

Thanks a lot for your kind reply.
its working fine. But after clicking on Export to Excel link im calling AutoIT Script.

Anyway thanks.

I need one more help buddy.

In my case i'm running same script in all browsers. So I need a script for all browsers to download file.
So i need to use If else case to switch to AutoIT script based on browser.
Pleas help me by wrting script. Aswell as i want AutoIT script such a way where i can select desired folder to save file before downloading file.

When i click on IE as i mentioned in my previous post i will get below native window when i click on Export button.




And in Firefox i will get below window after clicking on Export Button to download excel file.




In Chrome the file will be auto downloaded to downloads folder after clicking on Export Button.

Please do help me in this matter. 



For more options, visit https://groups.google.com/d/optout.

Nikhil Srivastava

unread,
May 9, 2016, 12:45:36 PM5/9/16
to seleniu...@googlegroups.com
Hi Surin,

Glad to know it works for you.

There is no rocket science for writing Browser identification if-else scripts, You just need to pass browser as a parameter , so you can pass the same in your scripts.

Besides that, As per my knowledge if you want to store download files on any desired folder you can handle it using code for Chrome and Firefox.

For IE, you need to handle it manually(Need to change some settings for IE Browser Download Location for specific File Type).

Cheers,
Nikhil



bhawna arora

unread,
May 9, 2016, 1:59:21 PM5/9/16
to seleniu...@googlegroups.com
Hi All,

Please let me know can we automate window services using selenium webdriver?

Jerry Zhao

unread,
Jul 7, 2017, 12:59:22 AM7/7/17
to Selenium Users
Hello:

     I write an article which can dismiss the download popup dialog for Firefox and Chrome in selenium webdriver. Wish this can give you some help.


      For Firefox: You just need to set it' preferenece browser.helperApps.neverAsk.saveToDisk to you downloaded file mime type.

      For Chrome: You need to set options in it.

Jerry Zhao

Prabhanjan Desai

unread,
Sep 5, 2017, 3:07:39 AM9/5/17
to Selenium Users

Hi Surinder/Nikhil,

Can you please share the exact working auto it script for pop up appearing in IE.
I followed the steps which Nikhil told but unable to handle the popup and i executed auto it script after clicking on export to csv.

Thanks,
Prabhanjan

varun...@blueoptima.com

unread,
Feb 27, 2018, 10:55:47 AM2/27/18
to Selenium Users
Hi, 

I know this is a quite old post. But is there a way to click on Save/Close button, without having to get the focus on the tab? I was able to do it while having screen focus only. Is there a way in which we can accomplish the same without focus? 

Deepa Jalisatgi

unread,
Mar 14, 2018, 11:38:00 PM3/14/18
to Selenium Users
Hi Nikhil

Even i too have same issue with downloading file.
I tried to use your code same as you mentioned here.. but its not working could you pls help me out.

Am using IE -11, and Selenium version 3. 

Thank you,
Deepa Jalisatgi

On Monday, 25 April 2016 18:08:08 UTC+5:30, Nikhil Srivastava wrote:
Reply all
Reply to author
Forward
0 new messages