Skip to content Skip to sidebar Skip to footer

Selecting Element From Dropdown Without Id Capybara

I am trying to use capybara (ruby bindings) to select an item from a dropdown that does not have an id or unique class, but I seem to be unable to do so. The select box in question

Solution 1:

If you want more control over which option you select, you will need to:

  1. Find the option element (using find, all, etc)
  2. Use the select_option method

For example, if you wanted to just select the first option:

option = page.first("#panel > div.panel-body > form > div:nth-child(1) > select option")
option.select_option

Or if you wanted to select the last:

options = page.all("#panel > div.panel-body > form > div:nth-child(1) > select option")
options[-1].select_option

Post a Comment for "Selecting Element From Dropdown Without Id Capybara"