I'd like to find the first instance of a checkbox using the capybara dsl. Anyone know how to do that?
I thought perhaps it'd be this, but it didn't work:
find('input:first', :type => 'checkbox')
Assuming Capybara.default_selector is set to CSS then:
find("input[type='checkbox']")
If you're using XPath it will be different.
Update (June 2013): as @tmg points out, the behaviour for Capybara 2 has changed.
Just to point out tmg's right way to find the first checkbox
first("input[type='checkbox']")
If you want to find n-th checkbox (25-th for example):
find(:xpath, "(//input[@type='checkbox'])[25]")
But it's often better to use within to narrow your searching area
within 'div.div_class' do
find("input[type='checkbox']")
end
The least flaky way to find the first checkbox could be:
find("input[type='checkbox']", match: :first)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With