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 ListItemWrapper

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

Overview

Concrete tool for selecting HTML list item (`

  • `) elements by their label text provided by the Taiko browser automation library.

    Description

    `ListItemWrapper` is a specialized subclass of `ElementWrapper` that locates HTML `
  • ` (list item) elements on a page. It is a compact wrapper at only 21 lines of code. The constructor passes `"ListItem"` as the element type and `"label"` as the query type to the parent `ElementWrapper`. The `_get` method is set using the `getElementGetter()` helper from `./helper.js`. This helper builds the appropriate getter strategy based on the selector type:
    • If attribute-value pairs are provided, it constructs a CSS query for `
    • ` tags with those attributes.
    • If a label string is provided, it uses the `match()` function from `elementSearch` to find `
    • ` elements whose text content matches the label.
    • If neither is provided (bare selector or proximity-only), it matches all `
    • ` elements and relies on relative search arguments for filtering.

    Usage

    Use `ListItemWrapper` (via the `listItem()` selector in Taiko) when you need to interact with list items on a page. This is the appropriate selector for any `
  • ` tag within ordered (`
      `) or unordered (`
        `) lists, whether you are clicking on a list entry, verifying its existence, or reading its text content.

        Code Reference

        Source Location

        Signature

        class ListItemWrapper extends ElementWrapper {
          constructor(attrValuePairs, _options, ...args) {
            super('ListItem', 'label', attrValuePairs, _options, ...args);
            this._get = getElementGetter(
              this.selector,
              async () => await match(this.selector.label, this._options).elements('li', 0, 0),
              'li',
            );
          }
        }
        

        Import

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

        I/O Contract

        Inputs

        Name Type Required Description
        attrValuePairs string / Object / RegExp No A label string to match against the list item's visible text, an attribute-value pair object for CSS attribute matching, or a regular expression. When omitted, all `
      • ` elements are candidates.
      • _options Object No Options object passed through to the parent `ElementWrapper`.
        ...args RelativeSearchElement[] No Zero or more relative search elements (e.g., `near()`, `below()`) used for proximity-based filtering of results.

        Outputs

        Name Type Description
        ListItemWrapper ListItemWrapper An `ElementWrapper` instance representing all matched `
      • ` elements. Delegates to the first match for actions like `click()`, `exists()`, and `text()`.
      • Usage Examples

        Basic Usage

        const { openBrowser, goto, listItem, click, closeBrowser } = require('taiko');
        
        (async () => {
          await openBrowser();
          await goto('https://example.com');
          await click(listItem('Settings'));
          await closeBrowser();
        })();
        

        Check List Item Existence

        const { openBrowser, goto, listItem, closeBrowser } = require('taiko');
        
        (async () => {
          await openBrowser();
          await goto('https://example.com');
          const hasItem = await listItem('Dashboard').exists();
          console.log('Dashboard list item exists:', hasItem);
          await closeBrowser();
        })();
        

        With Attribute-Value Pairs

        const { openBrowser, goto, listItem, click, closeBrowser } = require('taiko');
        
        (async () => {
          await openBrowser();
          await goto('https://example.com');
          await click(listItem({ class: 'active' }));
          await closeBrowser();
        })();
        

        Related Pages

  • Page Connections

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