Class: Watir::Element
- Inherits:
-
Object
- Object
- Watir::Element
- Defined in:
- lib/watirsplash/frameworks/watir.rb
Instance Method Summary collapse
-
#save_as(file_path) ⇒ Object
saves a file with the browser.
Instance Method Details
#save_as(file_path) ⇒ Object
saves a file with the browser
clicking the button opens a browser’s save as dialog and saves the file document.pdf
(:id => "something").save_as("c:/document.pdf") # => c:/document.pdf
-
raises an exception if saving the file is unsuccessful
-
returns saved file path
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/watirsplash/frameworks/watir.rb', line 31 def save_as(file_path) path = Pathname.new(file_path) raise "path to #{file_path} has to be absolute!" unless path.absolute? self.click_no_wait browser_window = page_container.rautomation if page_container.class.version.to_i >= 9 browser_window.child(:title => "Windows Internet Explorer").(:value => "Save &as").click else browser_window.child(:title => "File Download").(:value => "&Save").click end save_as_window = browser_window.child(:title => "Save As") save_as_window.text_field(:class => "Edit", :index => 0).set(WatirSplash::Util.file_native_path(file_path)) save_as_window.(:value => "&Save").click Wait.until {File.exists?(file_path)} file_path end |