user3376010 user3376010 - 3 months ago 25
Ruby Question

XPath count not converting to Ruby number

I'm trying to introduce XPath to my Ruby on Rails, Cucumber and Capybara setup for the first time. My code

row_count_on_page = page.find(:xpath, "count(//table[@id='foo']/tbody/tr)")

is resulting in error

undefined method `map' for 10.0:Float
Did you mean? tap (NoMethodError)

The actual XPath part of the code seems to be working correctly because there are exactly ten rows in the body of the table. I don't get how the code can't convert that 10.0 into a Ruby 10 though. What am I doing wrong?


You should do the count outside the method.


As you are currently using, after the second member of find is evaluated you will have something like:

row_count_on_page = page.find(:xpath, "10.0")

which is not a valid xpath.