如何获取水豚黄瓜中的元素集合
全部!
可能我有一个表,
<tabel>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
</table>
我想用黄瓜步骤定义将它们填充到循环中,就像这样
table.hashes.each do |hash|
within(:xpath,"//div[@id='cycle_form']/table/tr#{table.hashes.index(hash)}") do
fill_in("schedule_of_working_new_cycle_attributes__day", :with => hash['day'])
fill_in("schedule_of_working_new_cycle_attributes__hour", :with => hash['hour'])
fill_in("schedule_of_working_new_cycle_attributes__hour_night", :with => hash['hour_night'])
end
end
我得到@ Unable to find xpath "//div[@id='cycle_form']/table/tr[0]" @
我如何获取集合与水豚的元素?
all!
Possible I have a table
<tabel>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
<tr><td><input type=text/></td><td><input type=text/></td></tr>
</table>
I want fill them in cycle with cucumber step definition like this
table.hashes.each do |hash|
within(:xpath,"//div[@id='cycle_form']/table/tr#{table.hashes.index(hash)}") do
fill_in("schedule_of_working_new_cycle_attributes__day", :with => hash['day'])
fill_in("schedule_of_working_new_cycle_attributes__hour", :with => hash['hour'])
fill_in("schedule_of_working_new_cycle_attributes__hour_night", :with => hash['hour_night'])
end
end
I get @ Unable to find xpath "//div[@id='cycle_form']/table/tr[0]" @
How can i get collection of elements with capybara?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是 XML 的问题,因此假设它看起来像这样:
这将起作用:
另一件事是 XPath 索引从 1 而不是 0 开始,因此您的原始查询将不起作用。
仔细检查输入 XML 并更正迭代的起始值,它应该可以工作。
It might be an issue with the XML, so presuming it is meant to look like this:
This will work:
The other thing is that XPath indexing begins at 1 not 0, so your original query wouldn't have worked any way.
Double check the input XML and correct the starting value for the iteration and it should work.