Capybara Ambiguity Resolution
My solution is first(:link, link).click instead of click_link(link)
My solution is first(:link, link).click instead of click_link(link)
Use a regexp instead of a string for the value of the :text key: find(“a”, :text => /\ABerlin\z/) Check out the ‘Options Hash’ section of the Method: Capybara::Node::Finders#all documentation. PS: text matches are case sensitive. Your example code actually raises an error: find(“a”, :text => “berlin”) # => Capybara::ElementNotFound: # Unable to find css “a” … Read more
If you are in Ubuntu do sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui If you are on Mac brew install qt and then gem install capybara-webkit -v ‘0.11.0’
I found the following worked for me: # Check find(:css, “#cityID[value=”62″]”).set(true) # Uncheck find(:css, “#cityID[value=”62″]”).set(false)
You can just use: first(‘.item’).click_link(‘Agree’) or first(‘.item > a’).click (if your default selector is :css) Code in your question doesn’t work as: within “.item” do first(:link, “Agree”).click end is equivalent to: find(‘.item’).first(:link, “Agree”).click Capybara finds several .item‘s so it raises an exception. I consider this behavior of Capybara 2 very good.
For some reason it didn’t work for me. So I had to use something else. select “option_name_here”, :from => “organizationSelect” worked for me.
I’ve updated this answer to reflect modern conventions in capybara. I think this is ideal since this is the accepted answer, and what many people are being referred to when looking for a solution. With that said, the correct way to check the current path is to use the has_current_path? matcher provided by Capybara, as … Read more
Another pretty solution would be: page.should have_field(‘Your name’, with: ‘John’) or expect(page).to have_field(‘Your name’, with: ‘John’) respectively. Also see the reference. Note: for disabled inputs, you’ll need to add the option disabled: true.