1
votes

I'm trying to download some .xls file using selenium WebDriver with ChromeDriver and PhantomJSD (for background mode). It's works just perfect with ChromeDriver, but PhantomJS doesn't download the file.

So what is my code simplly do is login some website and click this button:

<button id="btnExcelExport" aria-label="יצוא נתונים" class="" data-tooltip="יצוא לאקסל"> </button>

When the button have been clicked, an frame created with link:

<iframe src="/Online/ExportExcel.ashx?ExportParameter=ExportToExcel&amp;Action=75273143-ee19-47ad-91ac-1377fe3c8875&amp;Alias=428" style="display: none;"></iframe>

Since I found out that PhantomJS doesn't support downloading, I tried to manually downlaod the file by using this code link with some small modification to match it to my code.

In result, it downloading the html file code of the login page.

How can I manage to download this file?

(or should I give up on PhantomJS but I couldn't found an easy repalcement..)

Thanks!

1

1 Answers

2
votes

I've come across this article in the past (http://collectiveidea.com/blog/archives/2012/01/27/testing-file-downloads-with-capybara-and-chromedriver/). It essentially describes how to set up the chrome driver's profile preference for downloads. After all, the driver is simply running your native chrome binary. I hope this helps in your sleuthing.

In summary, something like this should tell your driver where to download:

require "selenium/webdriver"

Capybara.register_driver :chrome do |app|
  profile = Selenium::WebDriver::Chrome::Profile.new
  profile["download.default_directory"] = "YOUR_DOWNLOAD_PATH"
  Capybara::Selenium::Driver.new(app, :browser => :chrome, :profile => profile)
end

Capybara.default_driver = Capybara.javascript_driver = :chrome

Now all you have left to handle is the download process in general which the above link describes. The process described in the article is written in Ruby, but should easily be translated to any other language.