Webdriver to save the excel sheet

2,627 views
Skip to first unread message

Rajendra

unread,
Sep 26, 2012, 7:38:57 AM9/26/12
to seleniu...@googlegroups.com
Hi All,
 
I have a scenarion,where i have to download excel file and save it on my local drive, Will driver supports to Click on "Save" /Open while donwloading the Excel sheet?

Amit Kumar Singh

unread,
Sep 26, 2012, 8:44:54 AM9/26/12
to seleniu...@googlegroups.com

Use following AUTOIT script:

 

WinWait("[Class:MozillaDialogClass]")

WinActivate("[Class:MozillaDialogClass]","")

Send("!s");

Send("{ENTER}")

 

Try out this and let me know?

 

Thanks

-Amit

--
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/-/-XxZ6V3XhUoJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 




Impetus Ranked in the Top 50 India’s Best Companies to Work For 2012.

Impetus webcast ‘Designing a Test Automation Framework for Multi-vendor Interoperable Systems’ available at http://lf1.me/0E/.


NOTE: This message may contain information that is confidential, proprietary, privileged or otherwise protected by law. The message is intended solely for the named addressee. If received in error, please destroy and notify the sender. Any use of this email is prohibited when received in error. Impetus does not represent, warrant and/or guarantee, that the integrity of this communication has been maintained nor that the communication is free of errors, virus, interception or interference.

Rajendra

unread,
Sep 27, 2012, 12:36:04 AM9/27/12
to seleniu...@googlegroups.com
Thanks Amit for your reply, But my organisation restricted us not to use any third party tool, So i want to know ,Do we have any way that can support with in webdriver
 
 
Thanks and Regards
Rajendra Chary.M

On Wednesday, September 26, 2012 6:15:10 PM UTC+5:30, Amit wrote:

Use following AUTOIT script:

 

WinWait("[Class:MozillaDialogClass]")

WinActivate("[Class:MozillaDialogClass]","")

Send("!s");

Send("{ENTER}")

 

Try out this and let me know?

 

Thanks

-Amit

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Rajendra
Sent: Wednesday, September 26, 2012 5:09 PM
To: seleniu...@googlegroups.com
Subject: [selenium-users] Webdriver to save the excel sheet

 

Hi All,

 

I have a scenarion,where i have to download excel file and save it on my local drive, Will driver supports to Click on "Save" /Open while donwloading the Excel sheet?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To post to this group, send email to seleni...@googlegroups.com.
To unsubscribe from this group, send email to selenium-use...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/-XxZ6V3XhUoJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Amit Kumar Singh

unread,
Sep 27, 2012, 1:07:21 AM9/27/12
to seleniu...@googlegroups.com

@Rajendra

Alternatively you can use browser capability or do some settings on profile that do not ask to save the file location. This leads to download the file behind the scene  and then sort the dir with java code and read the file , whatever you want to do with that file J.

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/-/ieeOkei2QkIJ.


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

Neeraj Sharma

unread,
Sep 27, 2012, 1:15:21 AM9/27/12
to seleniu...@googlegroups.com
+1 Amit, Yes we can set up a profile in which it don't ask for the yes and No option and directly download the file to the given path.

Neeraj Sharma.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ieeOkei2QkIJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

jeevan

unread,
Sep 27, 2012, 1:16:22 AM9/27/12
to seleniu...@googlegroups.com
Hi rajendra,

Before trying any other tool..please have a look at the useful content:  http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/ 


Thanks,
Jeevan.

Santosh Hulisandra Srikanta

unread,
Sep 27, 2012, 1:59:31 PM9/27/12
to seleniu...@googlegroups.com
Selenium /Webdriver can access the elements only with in the dom so it wont be possible through Selenium/ Webdriver i what i feel

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/-/ieeOkei2QkIJ.

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



--

/Santosh

Neeraj Sharma

unread,
Sep 27, 2012, 10:59:48 PM9/27/12
to seleniu...@googlegroups.com

Rajendra, can you please provide more information or screen shot, what you want to do?

Shreyas

unread,
Sep 27, 2012, 11:52:58 PM9/27/12
to seleniu...@googlegroups.com
Hi Rajendra,

Try using Java Robot Class. I have used this extensively in my scripts for Uploading/Downloading Files.

Documentation
- http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Robot.html

Example - http://www.java-tips.org/java-se-tips/java.awt/how-to-use-robot-class-in-java.html

Regards,
Shreyas Chaudhari.

Neeraj Sharma

unread,
Sep 28, 2012, 9:59:51 AM9/28/12
to seleniu...@googlegroups.com
Hi Rajendra,

To download a file without prompting the save/ open with pop up window, you first need to create a profile for the firefox, here is a example to create a profile by which it automatically save the downloaded file into the hard disk. In this you need to add the MIME extension of your downloading file.
For more info on MIME extension:-



   FirefoxProfile profile = new FirefoxProfile(); 

   profile.setPreference("browser.download.folderList", 2);  //   (browser.download.folderList are internal methods of the FF profile and 2 is the                                                    corresponding value of the location.)
   profile.setPreference("browser.download.dir","C:\\Users\\neeraj\\Downloads\\neeraj"); //  path where I have to store the file.
   profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword,application/csv,text/csv"); //Add the MIME code of your file here.
//  profile.setPreference("browser.download.manager.showWhenStarting", "false");
  profile.setPreference("browser.download.useDownloadDir", "false");  
 
  
   WebDriver driver = new FirefoxDriver(profile);

The detail for each internal firefox methods are:
1) browser.download.folderListTrue (default): Without asking a location, download files to the directory specified in browser.download.folderList
False: Ask where to save every file
Note: In Firefox, this can be changed via "Tools → Options → Main / Downloads → Always ask me where to save files (Firefox 2 and above) or Downloads / Download Folder → Ask me where to save every file" (Firefox 1.5)

2) browser.download.useDownloadDir    ----Determines the directory to download to when browser.download.useDownloadDir is false. Appears to mirrorbrowser.download.dir.

3)browser. download. dir--The last directory used for saving a file from the "What should (browser) do with this file?" dialog.

4)browser. helperApps. neverAsk. saveToDisk-A comma-separated list of MIME types to save to disk without asking what to use to open the file. Default value is an empty string.


Thanks,
Neeraj Sharma.

Rajendra

unread,
Oct 3, 2012, 8:11:20 AM10/3/12
to seleniu...@googlegroups.com

Rajendra

unread,
Oct 3, 2012, 8:13:24 AM10/3/12
to seleniu...@googlegroups.com


On Wednesday, October 3, 2012 5:41:20 PM UTC+5:30, Rajendra wrote:

Hi Neeraj,
 
I tried this,But i am not able to achieve it, But finally i found that ,where i am doing the mistake:
 
I have been using
 fp.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/ms-excel");
 
but it should be
fp.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel");
 
Thanks for giving a valuable reply
 
Regards

Neeraj Sharma

unread,
Oct 3, 2012, 8:21:25 AM10/3/12
to seleniu...@googlegroups.com
I am glad to know that your problem was solved now,, :)

Dan Franko

unread,
Nov 12, 2012, 12:05:17 PM11/12/12
to seleniu...@googlegroups.com

So, all of the above works well for Firefox and Chrome, but this won't work for IE.  I've found that for IE the alert api works pretty well.  In short, if you right click on the link to the file and then use the keyboard shortcut to save as, you can then set the path on the dialog and click to save, all without having to use anything other than webdriver.  This also seems to work much better than autoit or anything else when running on a machine that's locked.

For example using watir-webdriver/ruby.

#Click the link and choose save_as 

b.link(:text => @filename).when_present.right_click
b.send_keys("A")

# Set the path and then click 'Save'

b.alert.set(path)
b.alert.ok

Mark Collin

unread,
Nov 12, 2012, 4:15:48 PM11/12/12
to seleniu...@googlegroups.com

 

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Rajendra
Sent: 26 September 2012 12:39
To: seleniu...@googlegroups.com
Subject: [selenium-users] Webdriver to save the excel sheet

 

Hi All,

 

I have a scenarion,where i have to download excel file and save it on my local drive, Will driver supports to Click on "Save" /Open while donwloading the Excel sheet?

--

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.

Daniel Kaminski

unread,
Jun 26, 2014, 12:40:45 PM6/26/14
to seleniu...@googlegroups.com
After you get the handle for the popup dialog MozillaDialogClass, then simply PostMessage(hWnd, (uint)WM_KEYDOWN, (int)VKeys.VK_RETURN, 0);

This will send the ENTER key directly to the dialog and it will download the file
Reply all
Reply to author
Forward
0 new messages