Firefox 4 with watir webdriver: Need help using helperApps.neverAsk to save CSV without prompting

后端 未结 2 1869
你的背包
你的背包 2021-01-06 00:08

I learned how to use Firefox 4 with watir and webdriver (on Win7 x64), setting profile items. Example:

profile = Selenium::WebDriver::Firefox::Profile.new
pr         


        
相关标签:
2条回答
  • 2021-01-06 00:16

    In Firefox 6+, I couldn't get this to work without specifically setting the 'browser.download.folderList' value:

    profile = Selenium::WebDriver::Firefox::Profile.new
    profile['browser.download.folderList'] = 2 #custom location
    profile['browser.download.dir'] = download_directory
    profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv, application/csv"
    b = Watir::Browser.new :firefox, :profile => profile
    

    See: http://watirwebdriver.com/browser-downloads/

    0 讨论(0)
  • 2021-01-06 00:20

    I've done some testing of this for you, unfortunately there doesn't seem to be a standard content-type for CSV files. You can try passing a comma separated list of content-types, hopefully one of those work for you. For me it was application/octet-stream that did the trick...

    require 'watir-webdriver'
    require 'selenium-webdriver'
    
    profile = Selenium::WebDriver::Firefox::Profile.new
    profile["browser.download.useDownloadDir"] = true
    profile["browser.download.dir"] = '/tmp'
    profile["browser.helperApps.neverAsk.saveToDisk"] = "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream"
    driver = Selenium::WebDriver.for :firefox, :profile => profile
    browser = Watir::Browser.new(driver)
    
    browser.goto "http://altentee.com/test/test.csv"
    
    0 讨论(0)
提交回复
热议问题