Reputation: 229
Hi I wanted to know how I can select a certain index in all select_list boxes on the screen. I was able to make them flash with this line of code:
browser.elements(:class => "level").each { |e| e.flash }
Due to lack of experience I am unable to figure out how to actually select the same index (the last option from drop down) from all the boxes.
Upvotes: 1
Views: 711
Reputation: 5283
If I'm following correctly, you want to select the last option for multiple dropdown menus.
Given some contrived HTML:
<select>
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
<select>
<option value="four">Four</option>
<option value="five">Five</option>
<option value="six">Six</option>
</select>
You can user the select_lists
method to collect the available select lists, and then iterate over that collection and select the last option for each:
lists = browser.select_lists
lists.each do |list|
list.options.last.select
end
Upvotes: 3
Reputation: 405
Maybe grab each select_list, map the value to an array and grab the last element in the array.
browser.select_lists(:class => "level").each do |e|
content = e.options.map(&:value)
lastElement = content[-1]
end
Upvotes: 1