Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara+Rspec how to match a part of tag attribute

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?

like image 314
aristofun Avatar asked May 25 '12 07:05

aristofun


2 Answers

Try using contains:

page.should have_xpath "//a[contains(@href,'page=2')]"
like image 186
jdoe Avatar answered Oct 20 '22 12:10

jdoe


Try this:

link = page.find('div.class ul li a')
link[:href].should match(/page=2/)

More information here.

like image 23
Nick Colgan Avatar answered Oct 20 '22 11:10

Nick Colgan