Upload file to an input area using FileApi

痞子三分冷 提交于 2019-12-24 16:19:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!