Skip to content

I.deselected()

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

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

Usage

javascript
I.deselected(option: string)
I.deselected(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
<!--[--><label>
  <input id="agree-checkbox" type="checkbox" name="terms" value="agree"> I agree to the terms and conditions.
</label>
<!--]-->

To assert that the checkbox is unchecked, use I.deselected(option):

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

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

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

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

Radio button group

Here's a group of radio buttons for illustration:

Door color

Frame color
Demo: Radio Button Group
UI
Door color

Frame color
HTML
<!--[--><div>
  <b>Door color</b><br>
  <label><input type="radio" name="door-color" value="r" checked="">Red</label>
  <label><input type="radio" name="door-color" value="g">Green</label>
  <label><input type="radio" name="door-color" value="b">Blue</label>
</div>
<br>
<div>
  <b>Frame color</b><br>
  <label><input type="radio" name="frame-color" value="r" checked="">Red</label>
  <label><input type="radio" name="frame-color" value="g">Green</label>
  <label><input type="radio" name="frame-color" value="b">Blue</label>
</div>
<!--]-->

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

js
// using group text
I.deselected("Door color", "Blue")

// using name attribute
I.deselected("door-color", "Blue")

Select dropdown

Here's a <select> dropdown for illustration:


Demo: Select Dropdown
UI

HTML
<!--[--><label for="country-field"><b>Country</b></label><br>
<select id="country-field" name="country">
  <option value="" selected="">Select Country</option>
  <option value="SG">Singapore</option>
  <option value="US">United States</option>
</select>
<!--]-->

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

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

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

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

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