Class: Watir::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/watirsplash/frameworks/watir.rb

Instance Method Summary collapse

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

button(: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").button(:value => "Save &as").click
  else
    browser_window.child(:title => "File Download").button(: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.button(:value => "&Save").click

  Wait.until {File.exists?(file_path)}
  file_path
end