How do I use Capybara to test that a form element is disabled when using jQuery's prop method?
Asked Answered
O

1

7

In my Rails 3 app, I've been using jQuery's attr() method to do things like this:

$('#application_dust_type_id').attr('disabled', 'disabled');

I would use Test/Unit, capybara and capybara-webkit to test this with:

assert page.has_selector? 'select[id=application_dust_type_id][disabled=disabled]'

Now, I'm trying to switch to using the prop method, as jQuery recommends:

$('#application_dust_type_id').prop('disabled', true)

But now the above assertion fails, even though the javascript still works the same in the browser.

How can I make an assertion based on an element's property (instead of an attribute) using capybara?

Osithe answered 19/12, 2012 at 14:25 Comment(0)
E
8

Try just checking for the existance of a disabled attribute as that is all that is really required to disable an input:

assert page.has_selector? 'select[id=application_dust_type_id][disabled]'

Note that the value of a disabled attribute is moot. You could set disabled="false" or disabled="foobar" and the element would be rendered as disabled.

Ebneter answered 19/12, 2012 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.