当input.file具有动态ID时,如何附加文件? [英] How do I attach a file when the input.file has a dynamic id?
本文介绍了当input.file具有动态ID时,如何附加文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个带有动态ID的陷阱。 attach_file命令需要输入type =file的id名称。问题是id是动态的
I have run into a snag with dynamic ids. The attach_file command needs the id name of the input type="file". The problem is that the id is dynamic
(id="document_22") #indicating the 22nd document uploaded to this section.
有办法获取元素的ID吗?
Is there a way to get the id of an element? something like...
attach_file(find(:xpath, ".//input[@name='file_upload']").get('@id'),
'C:\\Users\\testbox\\Documents\\testdoc.xls')
推荐答案
attach_file 只是将文件名传递给 Capybara :: Node :: Element#set
attach_file internally just passes filename to Capybara::Node::Element#set
method.
因此,您可以使用:
find(:xpath, ".//input[@name='file_upload']").set(filename)
这篇关于当input.file具有动态ID时,如何附加文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文