1
votes

I'm using headless watir-webdriver and I know that a particular action, browser.div.click prompts a file download. I know when you're using FF, you can specify a folder to download the file into but how can I handle a file download in headless? Is there a way to specify a folder, or better yet read it into memory?

Any help would be appreciated.

2
Wow, that's a tough one. I may try to look at it later. But instinct tells me it's a test to skip for automation.Dave McNulla
I'm actually not doing it for testing purposes but to fetch information from a site written in javascript. I know watir was built for tests, but I was looking for a way to interact with javascript sites. Mechanize doesn't have that functionality and I wasn't able to find any other options.asahi
Then try doing it with a browser. If that's not going to work, try a professional scraping tool. Good luck.Dave McNulla

2 Answers

0
votes

I'm not sure this is practical to test headless. how could anything headless prompt the user? I'd think you'd have to tell it where to send the file. This might be more of a question for the webdriver folks, that's their underlying functionality. You might just have to call it directly.

does the site implement a REST interface or a way to just get the file directly? Maybe try cURL or REST-CLient?

If the main purpose is just to download the file, then your first challenge is to see if you can figure out what the URL of the file is from the webpage code. If you can determine that, then have a look at the cURL gem you could use it (or just cURL from the command line) to invoke a get against the HTTP address for the file download, then save it to a file or work with it in memory as needed

0
votes

A possible solution can be to change the profile settings to display the binary content in the browser instead of opening a download dialog.