1

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.

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! Accomplished what I needed. Appreciate both answers.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.