Skip to content

I.selected()

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

If the matching element is not selected, the command fails the test.

Usage

javascript
I.selected(option: string)
I.selected(list: string, option: string)

Parameters

ParameterTypeDescription
liststring(optional) The group 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

Simple checkbox

Here's a simple checkbox for illustration:


Demo: Simple Checkbox
UI
HTML

To assert that the checkbox is checked, use I.selected(option):

js
// using text
I.selected("I agree")

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

// using css
I.selected("#agree-checkbox")

// using xpath
I.selected("//input[@name='terms']")

Radio button group

Here's a group of radio buttons for illustration:

Door color

Frame color
Demo: Radio Button Group
UI
HTML

To assert that the option in a specific group is selected, use I.selected(list, option):

js
// using group text
I.selected("Door color", "Red")

// using name attribute
I.selected("door-color", "Red")

Select dropdown

Here's a <select> dropdown for illustration:


Demo: Select Dropdown
UI
HTML

To assert that an option in a <select> group is selected, use I.selected(list, option):

js
// using labels
I.selected("Country", "Singapore")

// target option - by its `value` attribute
I.selected("Country", "SG")

// target dropdown - by `name` attribute
I.selected("country", "Singapore")

// target dropdown - by CSS or XPath
I.selected("#country-field", "Singapore")
I.selected("//select[@name='country']", "Singapore")