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 TextBox Element

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

Overview

Concrete tool for interacting with HTML text input and textarea elements provided by the Taiko browser automation library.

Description

The `TextBox` class extends the base `Element` class to represent `<input type="text">`, `<textarea>`, and other text-entry elements in the DOM. It is the simplest of the Element subclasses at only 25 lines. It provides a single `value()` method that retrieves the current content of the text field. The method first attempts to read the element's `value` property (appropriate for `<input>` and `<textarea>` elements); if no value is present, it falls back to reading `innerText` (appropriate for contentEditable elements or other text containers). Note that text entry itself (typing into the field) is handled by higher-level Taiko API functions (`write()`, `into()`), not by this class.

Usage

Use this class when you need to read the current value of a text input field, such as verifying form pre-fill data or asserting that typed text was correctly entered. Instances of `TextBox` are not created directly by library consumers. Instead, calling the Taiko API function `textBox()` returns an `ElementWrapper` that internally constructs `TextBox` instances via the static `TextBox.from(element, description)` factory method.

Code Reference

Source Location

Signature

class TextBox extends Element {
  async value() { ... }
  static from(element, description) { ... }
}

Import

// Internal class, accessed through Taiko API
const { textBox } = require('taiko');
// Returns ElementWrapper that creates TextBox instances internally

I/O Contract

Inputs

Name Type Required Description
element Element Yes (for `from`) Base Element instance to convert into a TextBox
description string Yes (for `from`) Human-readable description used in event logging

Outputs

Name Type Description
value() Promise<string> Returns the current text content of the element. Reads `this.value` first (for input/textarea); falls back to `this.innerText` for contentEditable elements.
from() TextBox Static factory that constructs a new TextBox from an existing Element instance.

Usage Examples

Basic Usage

const { openBrowser, goto, textBox, write, into, closeBrowser } = require('taiko');

(async () => {
  await openBrowser();
  await goto('https://example.com/form');

  // Type into a text field
  await write('John Doe', into(textBox('Full Name')));

  // Read back the current value
  const name = await textBox('Full Name').value();
  console.log('Name field value:', name); // "John Doe"

  // Read a pre-filled text field
  const email = await textBox('Email').value();
  console.log('Email field value:', email);

  await closeBrowser();
})();

Related Pages

Page Connections

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