How to check a checkbox in capybara?

前端 未结 13 1943
灰色年华
灰色年华 2020-11-30 23:34

I\'m using Rspec and Capybara.

How can I write a step to check a checkbox? I\'ve tried check by value but it can\'t find my checkbox<

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 23:59

    you can also use :xpath instead of :css if you have some problems finding it.

    find(:xpath , '//*[@id="example"]').set(true)

    on Chrome (and surely other browsers), you can "inspect element" and then by right clicking on the element you are interested in, there is 'copy xpath' if you don't know what xpath was, now you do.

提交回复
热议问题