How to check a checkbox in capybara?



  • 3 Answer(s)

    Follow this code:

    # Check
    find(:css, "#cityID[value='62']").set(true)
     
    # Uncheck
    find(:css, "#cityID[value='62']").set(false)
    

    Answered on January 12, 2019.
    Add Comment

    To create multiple elements with the same id it can easily check/uncheck a checkbox with elegant.

    check 'cityID'
    uncheck 'cityID'
    

    And checkbox with certain values,

    find(:css, "#cityID[value='62']").set(true)
    find(:css, "#cityID[value='62']").set(false)
    

    Check this link: capybara 

    Answered on January 12, 2019.
    Add Comment

    # Check
    find(:css, “#cityID[value=’62’]”).set(true)

    # Uncheck
    find(:css, “#cityID[value=’62’]”).set(false)

    It’s better not to create multiple elements with the same id, so that (and not only for that) you can easily check/uncheck a checkbox with elegant

    check ‘cityID’
    uncheck ‘cityID’
    If one can not avoid multiple elements with the same id and still needs to check a checkbox with certain value, he can do so with

    find(:css, “#cityID[value=’62’]”).set(true)
    find(:css, “#cityID[value=’62’]”).set(false)

    Answered on February 5, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.