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:

  1. the select list element retrieved locations_element instead of :locations.
  2. the list of options retrieved options instead of items.
  3. in if statement item != d_item changed item.text != d_item. assumption want compare option's text , d_item string.
  4. option elements not have select method. instead, use click 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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -