水豚:在范围内不会将操作限制在该元素内部

capybara: within scope does not restrict actions to inside of that element

有多种类似的 classes 和按钮,但我试图通过使用代码

单击特定 class 内的按钮
 within(first(locator, text: text))do
    scroll_to(first('button'))
    first('button').click
  end

来自

   <div class="some parent class"> 
         <div class="some other class" id="1">
               <div class="class1">......</div>
               <div class="class2">......</div>
               <div class="class of button">......</div>
            </div>
       <div class="class used inside within" id="2">
           <div class="class1">......</div>
           <div class="class2">......</div>
           <div class="class of button">......</div>
        </div>
</div>

但是当我 运行 我上面的代码时,它会点击 class some other class 内部的类似按钮,但不会在内部使用。任何建议我应该怎么做才能让它发挥作用。

还要检查我有 运行 first(locator, text: text) 并且找到的元素的路径是 class <div class="class used inside within" id="1">

的路径

好的,我让它工作了。事实上,我正在使用 page.execute_script("$('button').click()") 单击我的代码中的按钮,这似乎不限于特定的 class 通过在内部使用。但是现在我点击了没有脚本的纯水豚代码,它现在点击了正确的按钮