Method: Capybara::Node::Actions#attach_file
- Defined in:
- lib/capybara/node/actions.rb
#attach_file(locator, path) ⇒ Object
Find a file field on the page and attach a file given its path. The file field can be found via its name, id or label text.
page.attach_file(locator, '/path/to/file.png')
155 156 157 158 159 |
# File 'lib/capybara/node/actions.rb', line 155 def attach_file(locator, path) raise ::FileNotFound, "cannot attach file, #{path} does not exist" unless File.exist?(path.to_s) msg = "cannot attach file, no file field with id, name, or label '#{locator}' found" find(:xpath, XPath::HTML.file_field(locator), :message => msg).set(path) end |