使用FileApi将文件上传到输入区域 [英] Upload file to an input area using FileApi

查看:82
本文介绍了使用FileApi将文件上传到输入区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Capybara + RSpec capybara_webkit 作为驱动程序。还有一个使用FileApi的JS上传器。

我想在这里上传三个图像:

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/*">


当我单击选择照片按钮(在浏览器上)时,它会打开在典型的窗口中,我可以从计算机中选择3个文件

我想知道如何在水豚上复制它,因为当照片选择器打开时,我没有控件。我试图将图片添加到我的测试文件夹,并尝试:


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'))

但没有结果。

推荐答案

我终于找到了解决方案。我的输入区域的不透明度设置为 0 ,所以这就是为什么我无法附加文件的原因。
所以我需要设置其对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')")

这篇关于使用FileApi将文件上传到输入区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆