0

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

6
  • 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 herefor a code snippet Commented Aug 9, 2016 at 6:36
  • thanks @maxpleaner but I am looking for headless solution.
    – Unicornz
    Commented Aug 9, 2016 at 7: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. Commented Aug 9, 2016 at 8: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
    Commented Aug 10, 2016 at 5:42
  • See how-to-download-a-csv-file-using-phantomjs for info on downloading files with phantom. The recommendation seems t be to use Casper instead Commented Aug 10, 2016 at 8:42

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.