Can Selenium intercept the automatic downloads from a web browser to a known generic folder?

245 views
Skip to first unread message

Priya P

unread,
May 18, 2015, 8:43:15 PM5/18/15
to seleniu...@googlegroups.com
Can Selenium intercept the automatic downloads from a web browser to a known generic folder?

krishnan.ma...@gmail.com

unread,
May 18, 2015, 9:12:40 PM5/18/15
to seleniu...@googlegroups.com

In browsers such as firefox I believe you can do it using a custom firefox profile. But this not true for all browsers.

You might want to take a look at this blog post by Mark on this.

http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

-Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else"

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/73276d23-6830-4c3b-8fa6-e6517e3c2a3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Priya P

unread,
May 18, 2015, 11:53:59 PM5/18/15
to seleniu...@googlegroups.com
Thanks for the link, however I tried something more simple, but it doesn't work on a  MAC

what is the replacement for the command profile browser.helperApps.neverAsk.saveToDisk" on a MAC?

Following is my code:

                String path="/Users/"; 
                profile.setPreference("browser.download.folderList", 2);
                profile.setPreference("browser.download.dir", path);
                profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
                profile.setPreference("browser.helperApps.neverAsk.saveToDisk","image/jpg, text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf");      
                
              
                WebDriver profileDriver = new FirefoxDriver(profile);
                profileDriver.get( "https://sampleqa.com");
                profileDriver.findElement(By.id("Username")).sendKeys("user");
                profileDriver.findElement(By.id("Password")).sendKeys("1234");
                profileDriver.findElement(By.xpath("//input[@type='submit']")).click();
                profileDriver.findElement(By.xpath("//a[@href='/admin/Dashboard/Information']")).click(); //click Dashboard tab


Krishnan Mahadevan

unread,
May 18, 2015, 11:59:10 PM5/18/15
to seleniu...@googlegroups.com
Priya,

What you are looking for now, is more of a  Firefox browser question than a Selenium query !
http://stackoverflow.com/a/15954999 should help you get started.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


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

Mark Collin

unread,
May 26, 2015, 2:20:45 AM5/26/15
to seleniu...@googlegroups.com
Hmm, so you tried something more simple, but it didn’t work...

You may want to re-evaluate your solution if cross browser/platform compatibility is important to you. :)  

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

Priya P

unread,
May 26, 2015, 6:10:52 PM5/26/15
to seleniu...@googlegroups.com
hey Mark,

I tried to get user's directory and pointed the downloads to that directory to get it to work :)

Regards
Priya

Mark Collin

unread,
May 27, 2015, 1:49:59 AM5/27/15
to seleniu...@googlegroups.com
So what are you doing with the files you download, are you checking them?

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

Priya P

unread,
May 27, 2015, 7:41:33 AM5/27/15
to seleniu...@googlegroups.com
Yes, my scenario is, I make some changes on our internal server, and export the Spreadsheet and verify that the changes are captured in the spreadsheet... The reason it was important for me to get a known file path is, when my automation code is executed on another team members pc, my code gets their user directory , places the downloaded file there. Then I write a read from excel from that path to verify my changes in the spreadsheet

Mark Collin

unread,
Jun 20, 2015, 4:02:24 AM6/20/15
to seleniu...@googlegroups.com
So I would argue that you don’t need to use Selenium to do this downloading and checking. You should write a Java class to do it for you (as I suggested on my blog post).
> On 27 May 2015, at 12:41, Priya P <priyasi...@gmail.com> wrote:
>
> Yes, my scenario is, I make some changes on our internal server, and export the Spreadsheet and verify that the changes are captured in the spreadsheet... The reason it was important for me to get a known file path is, when my automation code is executed on another team members pc, my code gets their user directory , places the downloaded file there. Then I write a read from excel from that path to verify my changes in the spreadsheet
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0272fd69-c77f-45b1-aacb-545eed147ec7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages