Lapis Lazuli:How to select an option in a dropdown

From Test Automation Wiki
Revision as of 17:52, 15 November 2016 by RoelofvA (talk | contribs) (Created page with "== How to select an option in a dropdown == This section will describe how to select an option in both a custom and a native dropdown. === Selecting an option in a custom dro...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to select an option in a dropdown

This section will describe how to select an option in both a custom and a native dropdown.

Selecting an option in a custom dropdown

To select an option from a custom dropdown, you will most likely have to open the dropdown first, to be able to select an option in the dropdown.

First find the dropdown and click it:

dropdown = browser.find(:like => ['element', 'attribute', 'include'])
dropdown.click

Then wait for the dropdown to unfold and select the option:

option = browser.wait(:like => ['element', 'attribute', 'include'])
option.click

Selecting an option in a native dropdown

To select an option from a native dropdown, you will not have to open the dropdown first. There are multiple ways to select an option from a native dropdown. A non extensive list of these options is presented below:

You can simply select the option by searching for it and clicking it. Please note that this is not a best practice method and is only usable on a page with a single dropdown.

option = browser.find(:like => ['element', 'attribute', 'include'])
option.click

A best practice is to first look for the dropdown in the code and then select the option you are looking for, by using to_subtype.select_value(some value).

browser.find(:like => ['element', 'attribute', 'include']).to_subtype.select_value('''some value''')