DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

attach a file in Capybara

🔗 Parent Note

🤔 Situation

You want to atach a file to the input tag.

<label for='data-file'>Data File</label>
<input type="file" name="files" id="attach_files">
Enter fullscreen mode Exit fullscreen mode

👍 Usual solution

Capybara::Node::Actions#attach_file

attach_file('data-file', 'path/to/file.csv')
Enter fullscreen mode Exit fullscreen mode

🦄 Workaround solution

find('form input[type="file"]').set('path/to/file.csv')
Enter fullscreen mode Exit fullscreen mode

📚 Attach A File With Capybara - Today I Learned

Top comments (0)