Implementation:Getgauge Taiko Button
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Form_Interaction |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for locating and interacting with button elements provided by the Taiko library.
Description
The button API creates a ButtonWrapper instance that represents one or more button elements on the page. It accepts either a label string (the visible button text) or an attribute-value pairs object to identify the target button, along with optional proximity selectors for disambiguation.
ButtonWrapper extends ElementWrapper directly, providing core interaction and assertion methods. The wrapper implements a dual search strategy:
- Input elements first — Searches for
<input>elements withtypeset tosubmit,reset,button, orimage, matching against thevalueattribute. - Button elements second — Falls back to searching
<button>elements, matching against their text content.
This ordering ensures that buttons are found regardless of the HTML pattern used by the application. The wrapper uses lazy element resolution with built-in retry logic, deferring the actual DOM query until an action or assertion method is called.
Usage
Use button() to:
- Locate buttons for click operations — Find and click submit, reset, or action buttons.
- Assert button existence — Verify that a specific button is present on the page.
- Check button state — Determine whether a button is visible, disabled, or enabled.
Code Reference
Source Location
- Repository: Taiko
- File:
lib/taiko.js:L1671-1675(button API entry point) - File:
lib/elementWrapper/buttonWrapper.js:L54-79(ButtonWrapper class)
Signature
button(attrValuePairs, _options, ...args) -> ButtonWrapper
Import
const { button, click } = require('taiko');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| attrValuePairs | string or Object | Yes | Button label text (e.g., 'Submit') or attribute-value pairs object (e.g., { id: 'submit-btn', class: 'primary' }) used to identify the target button element.
|
| _options | Object | No | Additional options for element resolution. |
| ...args | RelativeSearchElement[] | No | Proximity selectors such as near(), above(), below(), toLeftOf(), or toRightOf() used to disambiguate when multiple matching buttons exist.
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | ButtonWrapper | A wrapper object providing exists(), text(), isVisible(), isDisabled(), and elements() methods. Extends ElementWrapper. |
Usage Examples
Check button existence by text
// Verify that a button labeled 'Submit' exists on the page
await button('Submit').exists();
Click a button
// Click the button labeled 'Login'
await click(button('Login'));
Check disabled state by attribute
// Determine whether the submit button is currently disabled
const disabled = await button({ id: 'submit-btn' }).isDisabled();
Disambiguate with proximity selector
// When multiple 'Delete' buttons exist, use near() to target the correct one
await button('Delete', near('User Profile')).exists();