The select list elements have an options
method that returns an array of its option elements. You could iterate over the array and compare them to the d_item
.
The method could be:
def select_item_different_than d_item
list_items = locations_element.options
list_items.each do |item|
if item.text != d_item
item.click
return
end
end
end
Note that the following changes were required:
- The select list element is retrieved by
locations_element
instead of:locations
. - The list of options is retrieved by
options
instead ofitems
. - In the if statement
item != d_item
was changed toitem.text != d_item
. My assumption is that you want to compare the option's text andd_item
is a string. - Option elements do not have a
select
method. Instead, use theclick
method.
Personally, I think the method might be more clear as:
def select_item_different_than d_item
locations_element
.options
.find{ |option| option.text != d_item }
.click
end