pageobjects - How can we get all element values, when more than element hold same class name -
how can element values, when more element hold same class name.
eg: consider i'm having n number of elements having same class name follows
<span class="country-name">country 1</span> <span class="country-name">country 2</span> <span class="country-name">country 3</span> <span class="country-name">country 4</span> <span class="country-name">country 5</span>
how can element values having class name country_name.
also have tried follows:
span(:country, :class => 'country-name') puts country
when execute it, only printing first value (country 1) other values not printed. how can values?
any suggestions?
you can create collection accessor returns of related spans (ie class "country-name").
in page object, instead of calling span
, call pluralized version - spans
:
class mypage include pageobject spans(:country, :class => 'country-name') end
this create country_elements
method return returns array of matching spans. can iterate on array 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"
Comments
Post a Comment