问题
I'm using Capybara + RSpec and the capybara_webkit as driver. And a JS uploader with FileApi.
I'm trying to upload three images here:
<input type="file" name="image" multiple="" accept="image/*">
When I click on the "Select photos" button (on the browser), it opens the typical window where I can select 3 files from my computer.
I'd like to know how to reproduce it on capybara, as when the photos selector opens, I don't have the control on it. I tried to add the pictures to my tests folder and tried:
attach_file('image', File.absolute_path('../pictures/photo1.JPG'))
but with no results.
回答1:
I finally found a solution. My input area has opacity set to 0
, so that''s why i wasn't able to attach the files.
So i need to set its opacity to 1:
page.execute_script("$('input[name=file]').css('opacity','1')")
来源:https://stackoverflow.com/questions/33957287/upload-file-to-an-input-area-using-fileapi