在水豚标签标记上传文件 [英] Uploading file by label tag in capybara
问题描述
我通过使用水豚和黄瓜不能上传文件。
的HTML是以下
< DIV CLASS =DYN-CRM上传-BTN-容器>
<标签类=BTN BTN-主要BTN-SM数据绑定=可见:newCrmBtnEnabled,启用:fileEditEnabled>
< I类=发发加>< / I>
<跨度数据绑定=国际化:panels.partnerCrm.new数据的i18n =panels.partnerCrm.new>全新< / SPAN>
<输入ID =DYN-CRM文件输入级=DYN-CRM上传-BTNTYPE =文件名称=文件接受=数据绑定=事件:{变化CSV。 :setFileToNewName}>< /标签>
< / DIV>
如果我已经manualy选用的文件时,HTML是在一个新的div以下
< DIV数据绑定=可见:fileUploadVisible级=DYN-CRM文件上传的风格=>
<输入类型=文本数据绑定=值:fileToUpload.name,国际化:[占位符] panels.partnerCrm.fileUpload.enterNameMAXLENGTH =20级=K-DYN文本框的CRM文件名ID =dynCrmFilename数据值更新=KEYUP数据的i18n =[占位符] panels.partnerCrm.fileUpload.enterName占位符=文件名>
<输入类型=按钮数据绑定=点击:uploadFileCrmFile,国际化:[值] panels.partnerCrm.fileUpload.uploadVALUE =上传级=BTN BTN-主要数据的i18n =[值] panels.partnerCrm.fileUpload.upload>< DIV CLASS =文件上传正在进行容器>
< / DIV>
我已经试过这种
<$p$p><$c$c>attach_file(find('file',:visible=>false),File.absolute_path('C:/Users/user/test.csv'))这
attach_file(文件,File.absolute_path('C:/Users/user/test.csv'))
和其他一些变化,但我得到了以下错误
无法找到文件字段文件
或者使用ID时
无法找到文件域DYN-CRM文件输入
此外,我曾尝试attach_file上传之前执行一些脚本。
我用
黄瓜2.1.0
红宝石2.1.6
1.6.6.2引入nokogiri
2.4.4水豚
硒的webdriver 2.47.1
在此先感谢:)
EDITED
下面是链接的CSS图片:
CSS图片的。
正如我想象中,你将不得不使用jQuery修改显示:无
你的元素来显示:块
,例如:
要实现TIS,你可以用这个只是附加的文件之前尝试:
page.execute_script($('。DYN-CRM上传-BTN-容器')。CSS('显示器','块'))
I have problem uploading file by using capybara and cucumber.
The HTML is the following
<div class="dyn-crm-upload-btn-container">
<label class="btn btn-primary btn-sm" data-bind="visible: newCrmBtnEnabled, enabled: fileEditEnabled">
<i class="fa fa-plus"></i>
<span data-bind="i18n:panels.partnerCrm.new" data-i18n="panels.partnerCrm.new">NEW</span>
<input id="dyn-crm-file-input" class="dyn-crm-upload-btn" type="file" name="file" accept=".csv" data-bind="events: { change: setFileToNewName }"></label>
</div>
And if I have manualy choosed a file, the HTML is following in a new div
<div data-bind="visible: fileUploadVisible" class="dyn-crm-file-upload" style="">
<input type="text" data-bind="value: fileToUpload.name, i18n:[placeholder]panels.partnerCrm.fileUpload.enterName" maxlength="20" class="k-textbox dyn-crm-filename" id="dynCrmFilename" data-value-update="keyup" data-i18n="[placeholder]panels.partnerCrm.fileUpload.enterName" placeholder="File name">
<input type="button" data-bind="click: uploadFileCrmFile,i18n:[value]panels.partnerCrm.fileUpload.upload" value="Upload" class="btn btn-primary" data-i18n="[value]panels.partnerCrm.fileUpload.upload"><div class="file-upload-progress-container">
</div>
I have tried this
attach_file(find('file',:visible=>false),File.absolute_path('C:/Users/user/test.csv'))
And this
attach_file('file',File.absolute_path('C:/Users/user/test.csv'))
And some other variations, but I get the following error
Unable to find file field "file"
Or when using id
Unable to find file field "dyn-crm-file-input"
Also I have tried to execute some scripts before attach_file upload.
I'm using
cucumber 2.1.0
ruby 2.1.6
nokogiri 1.6.6.2
capybara 2.4.4
selenium-webdriver 2.47.1
Thanks in advance :)
EDITED
Here is the link for the css picture: css picture.
As I imagined, you will have to use jQuery to change the display:none
of your element to display:block
, for example.
To achieve tis, you can try with this just before attaching the file:
page.execute_script("$('.dyn-crm-upload-btn-container').css('display','block')")
这篇关于在水豚标签标记上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!