I.select

Select a dropdown, checkbox, or radio button.

Caveat

This only works on native HTML5 elements. If you have a custom element is not bound to an underlying native HTML5 element, use I.click as a fallback.

Usage

Select an option:
I.select(option)
Select an option in a list:
I.select(list, option)
Parameters
Parameter Type Remarks
list string Optional
Keyword to identify the options list.
Not case-sensitive.
option string Keyword to identify the option to select.
Not case-sensitive.

# Select dropdown option

Let's use this "Number" dropdown list for illustration.

Specify with option:

 I.select("Two");

This will select the option "Two" from the best matched dropdown list.

Identifying option

You can use the option's label or value to identify the option.
You can also use CSS or XPATH selectors to identify the option, however this should be used sparingly as it makes your test fragile, harder to read, and harder to maintain.

Specify with list and option:

Or, if there's multiple dropdown lists with the option "Two", you can be more specific and specify the list:

I.select("Number", "Two");

This will select the option "Two" from the dropdown list identified as "Number".

Identifying list

You can use the dropdown list's <label>, aria-label, name, current selected value, or nearby text to identify the list.
You can also use CSS or XPATH selectors, however this should be used sparingly as it makes your test fragile, harder to read, and harder to maintain.

# Select checkbox

Let's use this checkbox for illustration

I.select("I agree to the terms and conditions");

This selects the checkbox "I agree to the terms and conditions".

I.select("I agree");

Partial text also works, but note that other checkboxes that better match "I agree" may be selected instead.

Identifying option

The option can be matched by its <label>, aria-label, name, value, or nearby text.
You can also use CSS or XPATH selectors to identify the checkbox, however this should be used sparingly as it makes your test fragile, harder to read, and harder to maintain.

# Select a checkbox in a list

Let's use this "Color" checkbox list for illustration.

Specify with option;

I.select("Red");

This will select the option "Red" in the best matched checkbox list on the page.

Specify with list and option:

You can be more specific and specify the list and the option:

I.select("Color", "Red");

This will select the option "Red" in checkbox list identified as "Color" on the page.

Identifying list

You can use the option name or nearby text to identify the checkbox list.
You can also use CSS or XPATH selectors, however this should be used sparingly as it makes your test fragile, harder to read, and harder to maintain.

# Select a radio button

Let's use this "Animal" radio button list for illustration.

Specify with option:

I.select("Cat");

This will select the option "Cat" in the best matched radio button list on the page.

Identifying option

The option can be matched by its <label>, aria-label, name, value, or nearby text.
You can also use CSS or XPATH selectors, however this should be used sparingly as it makes your test fragile, harder to read, and harder to maintain.

Specify with list and option:

I.select("Animal", "Cat");

This will select the option "Cat" in the radio button list identified as "Animal" on the page.

Identifying list

You can use the option name or nearby text to identify the checkbox list.
You can also use CSS or XPATH selectors, however this should be used sparingly as it makes your test fragile, harder to read, and harder to maintain.