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?

croceldon
  • 4,511
  • 11
  • 57
  • 92

1 Answers1

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.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339