【问题标题】:How to get value of checkbox in capybara?如何在水豚中获取复选框的值?
【发布时间】:2017-10-07 14:04:58
【问题描述】:

我有这样的代码 html

<input type="checkbox" class="class-of-checkbox" value="facebook">

如何获取值(facebook)?

【问题讨论】:

  • 不是find(#class-of-checkbox).value 为您工作吗?您使用哪种语言?

标签: automation cucumber capybara qa


【解决方案1】:

您首先需要唯一地找到该元素,然后对其调用value。您如何唯一地找到元素可能高度依赖于页面其余部分的结构,但仅基于您提供的单个元素 HTML(并且您实际上不知道该值已经是什么)以下任何一种都可能是起点

find('.class-of-checkbox').value
find_field(type: 'checkbox', class: 'class-of-checkbox').value

如果您只是想验证具有期望的元素的值,那么您可以这样做(假设 RSpec 带有黄瓜)

expect(page).to have_field(type: 'checkbox', with: 'facebook', class: 'class-of-checkbox')  # you can also pass :checked option if you want to verify it is checked - or use have_checked_field/have_unchecked_field

【讨论】:

    猜你喜欢
    • 2012-01-08
    • 2021-03-28
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    相关资源
    最近更新 更多