Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# testing file Download
Hi,
I am now using the selenium RC with C#. I want to download a file from application. when I am clicking on a button one pop-up dialog box is coming which tells open,save and cancel. I am not able to handle this type of pop-up through selenium RC(C#).
 
Can anyone help me on this to resolve it as soon as possible.
 
Thanks in advance,
Dinesh
Posted 28-Dec-12 2:04am
Edited 28-Dec-12 2:05am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I ran into same issue using selenium, im making the assumption that when that box pops up you always wish to download it correct?
 
I ended up running my selenium through firefox and created a custom firefox profile in order to run it. In doing so i was able to say any file type of CSV automatically save it to c:\temp directory.
 
Here is my below MimeTypes.rdf and preferences.js for firefox. Using selenium you have the ability to run selenium using a custom firefox profile, this is well documented and plenty of examples on the internet that you should be able to easily find. A quick search found this link for example: http://garbuz.com/2010/07/31/running-selenium-with-custom-firefox-profile/[^]
 
mimeTypes.rdf (defines what files you want to auto download)
 
<rdf:rdf xmlns:nc="http://home.netscape.com/NC-rdf#" xmlns:rdf="#unknown">
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:description rdf:about="urn:root">
                   NC:en-US_defaultHandlersVersion="3" />
  <rdf:description rdf:about="urn:mimetype:application/vnd.ms-excel">
                   NC:value="application/vnd.ms-excel"
                   NC:editable="true"
                   NC:description="CSV document"
                   NC:alwaysAsk="false"
                   NC:saveToDisk="true">
    <nc:fileextensions>csv</nc:fileextensions>
    <nc:fileextensions>xls</nc:fileextensions>
    <nc:fileextensions>xlb</nc:fileextensions>
    <nc:fileextensions>xlt</nc:fileextensions>
    <nc:handlerprop rdf:resource="urn:mimetype:handler:application/vnd.ms-excel" />
  </rdf:description>
  <rdf:description rdf:about="urn:mimetype:handler:text/csv">
                   NC:saveToDisk="true"
                   NC:alwaysAsk="false" />
  <rdf:description rdf:about="urn:mimetype:text/csv">
                   NC:fileExtensions="csv"
                   NC:description="CSV document"
                   NC:value="text/csv"
                   NC:editable="true"
                   NC:alwaysAsk="false"
                   NC:saveToDisk="true">
      <nc:handlerprop rdf:resource="urn:mimetype:handler:text/csv" />
  </rdf:description>
</rdf:description></rdf:description></rdf:rdf>
 

preferences.js (you can basically take your current profile in firefox and add these two lines to it)
user_pref("browser.download.dir", "C:\\temp");
user_pref("browser.download.folderList", 2);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi Thanks David Wimbley,
I am using IE as my browser. So, i couldn't map your solution to my problem.
 
And i fixed the issue. All i did is go for using the help of ASCII Keycode values and WaitFor condition available in Selenium.
 
i,e,
                // Button - To Trigger File Download Button
                selenium.click(Button);
                selenium.waitForPageToLoad("10000");
                selenium.AltKeyDown();
                selenium.AltKeyUp();
                Thread.Sleep(3000);
                selenium.KeyPressNative("27"); ///27-ESC
                Thread.Sleep(3000);
 
 
This is the way i did, and found working fine.
 
Hi Ramasai, try this solution. all the best.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi Thanks David Wimbley,
 
I am using IE as my browser. So, i couldn't map your solution to my problem.

And i fixed the issue. All i did is go for using the help of ASCII Keycode values and WaitFor condition available in Selenium.

i,e,
 
                // Button - To Trigger File Download Button
                selenium.click(Button);
                selenium.waitForPageToLoad("10000");
                selenium.AltKeyDown();
                selenium.AltKeyUp();
                Thread.Sleep(3000);
                selenium.KeyPressNative("27"); ///27-ESC
                Thread.Sleep(3000);

 

This is the way i did, and found working fine.

Hi Ramasai, try this solution. all the best.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi I have the same problem butmy project is in IE. Can you guide me for a resolution in IE and I have used Selenium RC.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100