Skip to content

I.selected() ​

Asserts that a checkbox, radio button, or select dropdown option is currently selected.

If the element is selected, the assertion passes and the test script continues. If the element is not selected (or cannot be found), the test automatically retries until the command timeout is reached, then fails.

Usage ​

javascript
// assert that a uniquely identifiable option is selected
I.selected(option: string)

// assert that an option within a specific group or dropdown is selected
I.selected(list: string, option: string)

Parameters ​

ParameterTypeDescription
liststring(optional) The group or dropdown containing the option — by visible text, name attribute, CSS or XPath selector
optionstringThe option element to assert — by visible text, value, CSS or XPath selector

Examples ​

Checkbox ​

Here's a simple checkbox for illustration:


Demo: Simple Checkbox
UI
HTML

Assert that the checkbox is currently checked:

js
// using visible label (recommended)
I.selected("I agree")

// using option value
I.selected("agree")

// using CSS selector (visible inputs only)
I.selected("#agree-checkbox")

Hidden or Custom-Styled Checkboxes

When asserting state on custom-styled or hidden checkboxes, use the visible label text (e.g. I.selected("I agree")) to allow UI-licious to resolve the associated input element.

Radio button group ​

Here's a group of radio buttons for illustration:

Door color

Frame color
Demo: Radio Button Group
UI
HTML

When multiple groups share the same option labels, specify both the group and option:

js
// using group label and option label
I.selected("Door color", "Red")

// using group name attribute and option label
I.selected("door-color", "Red")

If the option label is unique across the page, you can assert it directly:

js
I.selected("Red")

Select dropdown ​

Here's a <select> dropdown for illustration:


Demo: Select Dropdown
UI
HTML

Assert that an option within a <select> dropdown is currently selected:

js
// using dropdown label and option text
I.selected("Country", "Singapore")

// using dropdown label and option value attribute
I.selected("Country", "SG")

// using dropdown name attribute and option text
I.selected("country", "Singapore")

// using dropdown CSS selector and option text
I.selected("#country-field", "Singapore")
CommandDescription
I.select()Check a checkbox or radio button, or select a dropdown option
I.deselected()Assert that an option, checkbox, or radio button is NOT selected
I.deselect()Uncheck an already checked checkbox

See Also ​