黄瓜测试:无法点击按钮

Cucumber test: Unable to click on button

我是黄瓜和 HTML 的新手。在我的测试中,我尝试使用 -> click_button('Check Inventory') 或 click_on('Check Inventory') 单击 "Check Inventory" 按钮。我收到此错误:

no button with value or id or text 'Check Inventory' found (Capybara::ElementNotFound)

我已经能够成功测试单击带有名称或值标签的按钮。所以我不确定标题标签的行为是否不同。这是 HTML:

<div id="inventory">
  <h4 class="border_bottom">Inventory</h4>
  <div><div class="check-inventory-btn btn-blue" title="Check Inventory">Available Inventory</div><label for="some stuff"><input id="some stuff" name="some stuff" type="checkbox" value="1">Some stuff here</label></div>
...
...
</div>

click_button 在 Capybara 中查找输入元素(类型为 submit、reset、image、button 或 image)和按钮元素。您的 "button" 是其中的 none,而是一个看起来像按钮的 div。要单击它,您需要找到该元素(通过 css 选择器等)并单击它。在这种情况下,

find(:css, 'div[title="Check Inventory"]').click

应该做你想做的事