You can create a collection accessor that returns all of the related spans (ie those with class "country-name").
In the page object, instead of calling span
, call the pluralized version - spans
:
class MyPage
include PageObject
spans(:country, :class => 'country-name')
end
This will create a country_elements
method that return returns an array of all matching spans. You can iterate over this array to get the text of each country (element):
page = MyPage.new(browser)
page.country_elements.each{ |c| puts c.text }
#=> "Country 1"
#=> "Country 2"
#=> "Country 3"
#=> "Country 4"
#=> "Country 5"