Implementation:Getgauge Taiko TextBox
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Form_Interaction |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for locating and interacting with text input fields provided by the Taiko library.
Description
The textBox API creates a TextBoxWrapper instance that represents one or more text input elements on the page. It accepts either a label string or an attribute-value pairs object to identify the target field, along with optional proximity selectors for disambiguation.
TextBoxWrapper extends ValueWrapper, which in turn extends ElementWrapper. This inheritance chain provides:
- ElementWrapper — Core methods such as exists(), elements(), text(), isVisible(), and isDisabled().
- ValueWrapper — The value() method for reading the current text content of the input.
- TextBoxWrapper — Specialized logic for identifying text input elements, including support for
<input>elements of various text-accepting types and<textarea>elements.
The wrapper uses lazy element resolution with built-in retry logic. The actual DOM query is deferred until an action or assertion method is called, ensuring that dynamically rendered fields are found even if they appear after the initial page load.
Usage
Use textBox() to target specific text input fields for:
- write() operations — Enter text into the field (commonly combined with into()).
- clear() operations — Remove existing text from the field.
- Assertions — Verify that a field exists, is visible, or contains an expected value.
Code Reference
Source Location
- Repository: Taiko
- File:
lib/taiko.js:L1868(textBox API entry point) - File:
lib/elementWrapper/textBoxWrapper.js:L85-111(TextBoxWrapper class)
Signature
textBox(labelOrAttrValuePairs, _options, ...args) -> TextBoxWrapper
Import
const { textBox, into, write } = require('taiko');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| labelOrAttrValuePairs | string or Object | Yes | Label text (e.g., 'First Name') or attribute-value pairs object (e.g., { id: 'username', placeholder: 'Enter email' }) used to identify the target text input field.
|
| _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 fields exist.
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | TextBoxWrapper | A wrapper object providing exists(), value(), elements(), text(), isVisible(), and isDisabled() methods. Extends ValueWrapper which extends ElementWrapper. |
Usage Examples
Find by label and write text
// Locate a text field by its associated label and enter a value
await write('John', into(textBox('First Name')));
Check existence by placeholder
// Verify a text field with a specific placeholder exists on the page
await textBox({ placeholder: 'Enter email' }).exists();
Read value by attribute
// Retrieve the current value of a text field identified by its id attribute
const username = await textBox({ id: 'username' }).value();
Disambiguate with proximity selector
// When multiple fields share the label 'Name', use near() to select the correct one
await write('value', into(textBox('Name', near('Profile Section'))));