Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Getgauge Taiko CheckBox Toggle

From Leeroopedia
Knowledge Sources
Domains Browser_Automation, Form_Interaction
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for toggling checkbox state (checked/unchecked) provided by the Taiko library.

Description

The checkBox() function creates a CheckBoxWrapper that provides idempotent methods for interacting with HTML checkbox elements. The check() method ensures the checkbox is checked (no-op if already checked), while uncheck() ensures it is unchecked (no-op if already unchecked). The isChecked() method inspects the current state without modifying it.

Checkboxes are located by their associated label text or attribute-value pairs. The idempotent design ensures consistent behavior regardless of the checkbox's initial state, which is critical for reliable test automation.

Usage

Use checkBox() when automating interactions with checkbox elements: accepting terms of service, toggling feature flags, selecting items in multi-select lists, or verifying that checkboxes are in the correct state after data loading.

Code Reference

Source Location

  • Repository: Taiko
  • File: lib/taiko.js (L1927-1931, checkBox API), lib/elementWrapper/checkBoxWrapper.js (L57-110, wrapper), lib/elements/checkBox.js (element)

Signature

checkBox(labelOrAttrValuePairs, _options, ...args) -> CheckBoxWrapper

Import

const { checkBox } = require('taiko');

I/O Contract

Inputs

Name Type Required Description
labelOrAttrValuePairs string / Object Yes Label text associated with the checkbox, or an object of attribute-value pairs (e.g., {id: 'agree-terms'}) to identify the checkbox element.
_options Object No Configuration options for element search behavior.
args RelativeSearchElement[] No Proximity selectors to narrow element search.

CheckBoxWrapper Methods

Method Signature Description
check check() -> Promise<void> Checks the checkbox if it is currently unchecked. No-op if already checked.
uncheck uncheck() -> Promise<void> Unchecks the checkbox if it is currently checked. No-op if already unchecked.
isChecked isChecked() -> Promise<boolean> Returns true if the checkbox is currently checked, false otherwise.
exists exists() -> Promise<boolean> Returns true if the checkbox element exists in the DOM.

Outputs

Name Type Description
return CheckBoxWrapper A wrapper object providing check(), uncheck(), isChecked(), and exists() methods for interacting with the checkbox.

Usage Examples

Check a Checkbox

// Check the 'Agree to Terms' checkbox
await checkBox('Agree').check();

Uncheck a Checkbox

// Uncheck the 'Agree to Terms' checkbox
await checkBox('Agree').uncheck();

Verify Checkbox State

// Assert that the checkbox is checked
const isChecked = await checkBox('Agree').isChecked();
console.log(isChecked); // true or false

Check by Attribute

// Find checkbox by its id attribute
await checkBox({id: 'newsletter-opt-in'}).check();

Check Existence

// Verify the checkbox element exists in the DOM
const exists = await checkBox('Agree').exists();
console.log(exists); // true or false

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment