user3376010 user3376010 - 1 year ago 95
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download