Capybara+Rspec how to match a part of tag attribute

capybara, rspec, ruby-on-rails

Solution

Try using `contains`:

page.should have_xpath "//a[contains(@href,'page=2')]"

Problem

I have a page with several links like that `<a href='/bla/bla/bla/?page=xxx>text</a>` I want to match certains `xxx` values links using Capybara and RSpec, i don't care about `bla/bla/bla` part of `href` attribute. ``` page.should have_selector("div.class ul li a", :href => "page=2") ``` doesn't work, also ``` page.should have_xpath("//a[@href='page=2']") ``` is not an option because i don't know the full `href` attribute value. PS: also didn't find any complete Capybara API documentation just to get all available methods and parameters' description. I there such thing?

Original source