Ste*_*eve 2 cucumber capybara ruby-on-rails-3
我无法让Cucumber"选择"一个单选按钮,并希望有人可以给我一个健全检查.没有引用大量的HTML垃圾,这里是相关部分(我从print.html收集).它位于由按钮激活的模态div中.我可以"点击"那个按钮并看到模态窗口出现(我在Selenium中将其作为@javascript场景运行).
<div class="modal-body pagination-centered">
<img src="/assets/payment.png" alt="Payment" />
<form novalidate="novalidate" method="post" id="edit_cart_1" class="simple_form edit_cart" action="/carts/complete" accept-charset="UTF-8">
<div style="margin:0;padding:0;display:inline">
<input type="hidden" value="?" name="utf8" />
<input type="hidden" value="put" name="_method" />
</div>
<div class="control-group hidden cart_property_id">
<div class="controls">
<input type="hidden" name="cart[property_id]" id="cart_property_id" class="hidden" />
</div>
</div>
<div id="payment_fat_buttons" class="fat-buttons">
<div class="vertical-button-wrapper">
<input type="radio" value="cash" name="cart[payment_type]" id="cart_payment_type_cash_pay" data-property-id="1" />
<label for="cart_payment_type_cash_pay">Cash</label>
</div>
<div class="vertical-button-wrapper">
<input type="radio" value="credit" name="cart[payment_type]" id="cart_payment_type_credit_pay" data-property-id="1" />
<label for="cart_payment_type_credit_pay">Credit</label>
</div>
</div>
<div style="display: none;" id="cart_room_number_area_pay">
<div class="control-group string optional cart_room_number">
<label for="cart_room_number_pay" class="string optional control-label">Room number</label>
<div class="controls">
<input type="text" value="" size="50" name="cart[room_number]" id="cart_room_number_pay" class="string optional" />
</div>
</div>
</div>
<input type="checkbox" value="1" style="display: none;" name="receipt" id="receipt" />
<div class="sell-modal-footer">
<input type="submit" value="Complete With Receipt" name="commit" id="cart_complete_with_receipt" data_disable_with="Processing..." class="btn btn-danger" />
<input type="submit" value="Complete Sale" name="commit" data_disable_with="Processing..." class="btn btn-danger" />
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了许多不同的方法来获得它,我能想到的.最明显的只是标签或ID,如:
choose 'cart_payment_type_cash_pay'
choose 'Cash'
Run Code Online (Sandbox Code Playgroud)
这只是给我错误:
Unable to find radio button "cart_payment_type_cash_pay" (Capybara::ElementNotFound)
Run Code Online (Sandbox Code Playgroud)
我认为它可能与模态对话框,可见性等有关,但我介绍了ID #payment_fat_buttons仅用于测试,当我查找它时:
find('#payment_fat_buttons').choose('Cash')
Run Code Online (Sandbox Code Playgroud)
它发现DIV OK,但仍然不是单选按钮.我也尝试在整个页面上使用xpath,并在以下范围内:
within(:xpath, "//div[@id='payment_methods']") do
find(:xpath, ".//input[@id='cart_payment_type_cash_pay']").choose
end
Run Code Online (Sandbox Code Playgroud)
它的行为也可以找到外部DIV,但不能找到单选按钮 - 我收到错误:
Unable to find xpath ".//input[@id='cart_payment_type_cash_pay']" (Capybara::ElementNotFound)
Run Code Online (Sandbox Code Playgroud)
通常,似乎我可以在单选按钮周围找到任意元素:xpath或CSS表达式,而不是单选按钮.我也可以毫无问题地按下表单上的提交按钮.我尝试删除数据属性作为测试 - 没有区别.任何帮助将不胜感激.这让我疯狂,因为它看起来很简单,但我无处可去.我需要为大部分场景选择它,所以如果我无法弄清楚,我将不得不求助于一些可怕的东西.提前谢谢了...
Gemfile.lock的相关版本:
rails (3.2.13)
cucumber (1.3.8)
gherkin (2.12.2)
cucumber-rails (1.4.0)
capybara (2.1.0)
selenium-webdriver (2.35.1)
Run Code Online (Sandbox Code Playgroud)
我终于想出了这一个.Capybara没有找到单选按钮,因为深埋在我的风格中的是一些隐藏它以改变外观的CSS.一旦我意识到这一点,我想通过只需点击标签就可以完成找到单选按钮的整个问题:
find(:xpath, "//label[@for='the_radio_button_id']").click
Run Code Online (Sandbox Code Playgroud)
我没有意识到可以通过这种方式获得单选按钮 - 但无论如何,它解决了如何点击Capybara因样式或其他问题而找不到的单选按钮的问题.希望能帮助别人.
| 归档时间: |
|
| 查看次数: |
2685 次 |
| 最近记录: |