iteration - How to iterate a select_list from Page Objects in Ruby -
i have page object has list item of locations.
select_list(:locations, :id => 'locations)
and have list of locations , select 1 of them. like:
def select_item_different_than d_item list_items = :locations.items #this wrong, point list_items.each |item| if item != d_item item.select return end end end
thanks lot :)
the select list elements have options
method returns array of option elements. iterate on array , compare them d_item
.
the method be:
def select_item_different_than d_item list_items = locations_element.options list_items.each |item| if item.text != d_item item.click return end end end
note following changes required:
- the select list element retrieved
locations_element
instead of:locations
. - the list of options retrieved
options
instead ofitems
. - in if statement
item != d_item
changeditem.text != d_item
. assumption want compare option's text ,d_item
string. - option elements not have
select
method. instead, useclick
method.
personally, think method might more clear as:
def select_item_different_than d_item locations_element .options .find{ |option| option.text != d_item } .click end
Comments
Post a Comment