I am using Watir Webdriver and a headless(phantomjs) browser to goto a website, login into it and click and download a file using javascript submit button.When I click on submit, I am redirected with 302 to a different address that i can see under my Network.This is url of the file to download.I am degugging using screenshots so i can see the phantomjs is working fine but after it hits on submit button, nothing happens.This whole procedure is working fine on firefox too.Using watir webdriver, how can i get that link and save it in database and redirect my phantomjs to download the file using that link?I tried reading github pull requests, official documentation and blog posts but i am unable to reach to any solution.Please provide me with suggestions or solutions. Even one word suggestion is also appreciated as it might help me to approach the problem.I have tried getting 'http request headers' but didn't succeed.I have browser.cookie.to_a
and browser.headers
is giving me only object
like this Watir::HTMLElementCollection:0x000000024b88c0
.Thank you
Asked
Active
Viewed 520 times
0

Unicornz
- 61
- 1
- 5
-
You need to use a custom Firefox profile. I recently figured out how to do this using selenium, though I haven't tried with Phantom. See [here](https://gist.github.com/MaxPleaner/9d73674916a64bf7f281eac5110972b8)for a code snippet – max pleaner Aug 09 '16 at 06:36
-
thanks @maxpleaner but I am looking for headless solution. – Unicornz Aug 09 '16 at 07:58
-
Actually I am using headless in the project where that code comes from. If you start headless before starting the firefox driver, it will be in headless scope. – max pleaner Aug 09 '16 at 08:10
-
thanks @maxpleaner , I found this code in the watir webdriver documentation and tried using it but unfortunately that code is working for firefox but not for phantomjs.I have added headers but still it is not working. – Unicornz Aug 10 '16 at 05:42
-
See [how-to-download-a-csv-file-using-phantomjs](http://stackoverflow.com/questions/31564215/how-to-download-a-csv-file-using-phantomjs) for info on downloading files with phantom. The recommendation seems t be to use Casper instead – max pleaner Aug 10 '16 at 08:42
-
Thank you @maxpleaner.I googled this topic and found that it can't be done in Phantomjs or may be i wasn't able to figureout how to do it.But i did it using watirwebdriver headless and firefox. – Unicornz Aug 26 '16 at 09:49
1 Answers
1
I was not to find solution to my question using Phantomjs but I have solved the problem using watirwebdriver(0.9.1) headless and firefox(44.0). These are the settings i have used.
profile = Selenium::WebDriver::Firefox::Profile.new
profile['download.prompt_for_download'] = false
profile['browser.download.folderList'] = 2 # custom location
profile['browser.download.dir'] = download_directory
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
profile['pdfjs.disabled'] = true
profile['pdfjs.firstRun'] = false
headless = Headless.new
headless.start
browser = Watir::Browser.new(:firefox, :profile => profile)
browser.goto 'www.google.com'
browser.window.resize_to(1280, 720)
puts browser.title
puts browser.url

Unicornz
- 61
- 1
- 5