如何获取水豚黄瓜中的元素集合

发布于 2025-01-03 22:27:03 字数 1123 浏览 0 评论 0原文

全部!

可能我有一个表,

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随波逐流 2025-01-10 22:27:03

这可能是 XML 的问题,因此假设它看起来像这样:

<div id="cycle_form">
    <table>
        <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>
</div>

这将起作用:

//div[@id='cycle_form']/table/tr[1]

另一件事是 XPath 索引从 1 而不是 0 开始,因此您的原始查询将不起作用。
仔细检查输入 XML 并更正迭代的起始值,它应该可以工作。

It might be an issue with the XML, so presuming it is meant to look like this:

<div id="cycle_form">
    <table>
        <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>
</div>

This will work:

//div[@id='cycle_form']/table/tr[1]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文