Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber Capybara find checkbox by other than id, name, or label

I'm trying to check a checkbox in my cucumber test, but I cannot figure out how to tell it to search by anything other than the id, name, or label. I keep on getting this error:

cannot check field, no checkbox with id, name, or label 'xxxx' found

I have added an attribute of 'identifier' to each checkbox, with unique values, and would like to find the box by these terms.

like image 484
Josh Johnson Avatar asked Nov 28 '11 17:11

Josh Johnson


2 Answers

Do you mean that you've added a new attribute named identifier to each checkbox? If so then you may be able to find them using a CSS locator:

find(:css, "[identifier='#{my_checkbox_identifier}']").set(true)

(set-ing the checkbox to true checks it, use false to uncheck it.)

like image 106
Jon M Avatar answered Sep 28 '22 00:09

Jon M


Realizing this question is rather old, an answer may still be useful to someone, somewhere. I found the following to work:

find(:xpath, "//input[@identifier='my_checkbox_identifier']").set(true)

like image 32
ampecho Avatar answered Sep 28 '22 00:09

ampecho