I have a select box, with a label:
<label for="slide_orientation">Slide orientation</label>
<select disabled="" class="property" id="slide_orientation" name="slide_orientation">
<option value="horizontal">Horizontal</option>
<option value="vertical" selected="selected">Vertical</option>
</select>
As you can see the select box is disabled. When I try to find it with field_labeled("Slide orientation")
, it returns an error:
Capybara::ElementNotFound: Unable to find field "Slide orientation"
from /Users/pascal/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.0.2/lib/capybara/result.rb:22:in `find!'
When the select box is not disabled, field_labeled("Slide orientation")
returns the select element just fine.
Is this expected behavior? And if so, how would I go about finding a disabled element? In my case I need it to test if it's disabled or not.
Capybara 2.1.0 supports disabled
filter. You can easily find disabled fields with it.
field_labeled("Slide orientation", disabled: true)
You need to specify it explicitly because the disabled
filter is off by default.
This one passes if it has the disabled attribute.
Run with js: true
and page.evaluate_script
.
it "check slider orientation", js: true do
disabled = page.evaluate_script("$('#slide_orientation').attr('disabled');")
disabled.should == 'disabled'
end
Update
or you can use have_css
page.should have_css("#slide_orientation[disabled]")
(stolen form this excellent answer )
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