addywaddy

addywaddy

addywaddy  //  

Nov 13 / 2:16pm

Counting Elements with XPath

I've been trying to figure out for the last couple of evenings how to check that a table in one of my specs has the correct amount of rows.Finally, I've found out how to do it:

  it "should have 10 rows" do
html = request("/resource/with/table").body
html.should have_xpath("//table/tbody/tr[count(../*)=10]")
end

I've no idea what the "../*" means but it works!

Update:

From the interweb ( http://www.zvon.org/xxl/XPathTutorial/Output/example1.html ):

"The basic XPath syntax is similar to filesystem addressing."

So, we're going up a level (..) and selecting all tr's in tbody (*).

0 comments

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    Connect    twitter