Case Study: Attempting to access an external URL using Capybara for downloading a file. It is necessary to use Selenium or Webkit as the driver, since Rack-test does not allow visiting external URLs.
This website utilizes iframes.
The prompt for file download is generated through javascript as shown below:
<a href="javascript:OpenFile('****.pdf', 2)">some_text_here</a>
When clicking the link, a browser-native download confirmation box appears. Various methods have been tried without success: Selenium driver:
using custom profile -> no impact, popup still displays
Capybara.register_driver :selenium do |app| profile = Selenium::WebDriver::Firefox::Profile.new profile['browser.download.dir'] = "~/Downloads" profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf" Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => >profile) end
using JavaScript before clicking link-> no effect
within_frame(1) do page.evaluate_script('window.confirm = function() { return true; }') find(:xpath,"//span[@class='BoldText']/a").click
attempting to utilize alert -> not found even when download box appears
page.driver.browser.switch_to.alert.accept -> No alert is present
Webkit driver:
trying to use javascript -> file is not being downloaded
page.accept_confirm not finding any links
How can the file be successfully downloaded?