I'm using RSpec2 and Capybara for acceptance testing.
I would like to assert that link is disabled or not in Capybara. How can I do this?
I'm using RSpec2 and Capybara for acceptance testing.
I would like to assert that link is disabled or not in Capybara. How can I do this?
Another simple solution is to access the HTML attribute you are looking for with
[]
:Note that
Capybara
will automatically try to wait for asynchronous requests to finish, but it may not work in some cases:Here is one workaround if you are having trouble with assertions on elements that are updated asynchronously:
bowsersenior, thanks for a hint
Here is an example:
It was a bit messy to find out the correct xpath, here is the correct one,
using capybara 0.4.1.1
If you only have a link without a class, use
Something like this will sadly not work:
The class option will be ignored.
have_link expects a hash of options which is empty if you do not provide any. You can specify any attributes the link should have - just make sure you pass all the options in ONE hash.
Hope this helps
PS: For attributes like data-method you have to pass the attribute name as a string since the hyphen breaks the symbol.
Whenever possible, you should try to use the Capybara provided wrappers which will work more consistently across drivers.
For the particular case of
disabled
, a wrapper was introduced in 2.1: https://github.com/jnicklas/capybara/blob/fc56557a5463b9d944207f2efa401faa5b49d9ef/History.md#version-210If you use it, you will get sensible results on both RackTest and Poltergeist:
HTML:
Tests:
Note how by using this instead of CSS selectors, the Javascript tests will work without any changes if you start using a Js capable driver.
Runnable test file here.
According to the docs you can use the [attribute] accessor syntax:
For disabled, you could also do this: