How to download an excel file and compare | Selenium Forum
M
Posted on 31/10/2015
Hi can anyone give the following please.
1) Download the excel file from the portal when we click in Export button.
a) in Chrome
b) in FireFox
c) in IE(In IE there is a open,save and cancel popup comes), how can we click on save button.
2) confirm it is downloaded (it directly downloads to default location)
3) Compare the downloaded excel sheet with the online table (headers, first and last row at least as it has many rows)

Please share the videos if you have any recorded.

Thanks

M
Replied on 01/11/2015

Use the robot class for downloading files.Through this class you can pass the keyboard keys like "Up","Down","Enter".It is mentioned in Module 15 last video.


M
Replied on 01/11/2015

for excel file this works




FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", "C:\\temp");
//profile.setPreference("browser.helperApps.neverAsk.openFile",
//"text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://qtpselenium.com/test/testdownload.php");
driver.findElement(By.xpath("html/body/a[1]")).click();


M
Replied on 02/11/2015

Hi Thanks for your reply.
The FF and Chrome are fine to set profiles, but IE there isn't any.
Please check IE 11 when we download a file it is giving the alert/popup in the footer of the page and I couldn't fine any Robot class in C# selenium. Please advice how to handle this. I have seen your video which is showing the popup in the middle as an alert and there is a class in Java as Robot but there are none in C#..

Thanks


M
Replied on 02/11/2015

i'm not that good at C#.

this link will help you on ie file download

http://sqa.stackexchange.com/questions/3169/downloading-a-file-in-internet-explorer-through-selenium
http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/


M
Replied on 02/11/2015

That did not help, could you at least tell me how to handle IE 11 save pop up when we try to download any file. I just need to click on save button to download in the default location. I have tried Autoit where I can spy pop up buttons in chrome but not in IE, pls help...


M
Replied on 02/11/2015

for java you use robot framework but for c# there are no classes like "robot"


M
Replied on 03/11/2015

Ok thanks
Can we do it with AUTOIT tool to click on Save button on the IE 11 download, is anyone tried ?


M
Replied on 03/11/2015

we don't have working code for IE, I'm afraid.