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 LinkWrapper

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

Overview

Concrete tool for selecting HTML anchor (`<a>`) elements by their text content provided by the Taiko browser automation library.

Description

`LinkWrapper` is a specialized subclass of `ElementWrapper` that locates HTML `<a>` (anchor) elements on a page. It is one of the simplest wrappers in Taiko, consisting of only 21 lines of code. The constructor passes `"Link"` as the element type and `"text"` 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 `<a>` tags with those attributes.
  • If a label string is provided, it uses the `match()` function from `elementSearch` to find `<a>` elements whose text content matches the label.
  • If neither is provided (bare selector or proximity-only), it matches all `<a>` elements and relies on relative search arguments for filtering.

Usage

Use `LinkWrapper` (via the `link()` selector in Taiko) when you need to interact with hyperlinks on a page. This is the appropriate selector for any `<a>` tag, whether you are clicking a navigation link, verifying its existence, or reading its text content.

Code Reference

Source Location

Signature

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

Import

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

I/O Contract

Inputs

Name Type Required Description
attrValuePairs string / Object / RegExp No A text string to match against the link's visible text, an attribute-value pair object for CSS attribute matching, or a regular expression. When omitted, all `<a>` 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()`, `above()`) used for proximity-based filtering of results.

Outputs

Name Type Description
LinkWrapper LinkWrapper An `ElementWrapper` instance representing all matched `<a>` elements. Delegates to the first match for actions like `click()`, `exists()`, and `text()`.

Usage Examples

Basic Usage

const { openBrowser, goto, link, click, closeBrowser } = require('taiko');

(async () => {
  await openBrowser();
  await goto('https://example.com');
  await click(link('More information...'));
  await closeBrowser();
})();

Check Link Existence

const { openBrowser, goto, link, closeBrowser } = require('taiko');

(async () => {
  await openBrowser();
  await goto('https://example.com');
  const hasAbout = await link('About').exists();
  console.log('About link exists:', hasAbout);
  await closeBrowser();
})();

With Attribute-Value Pairs

const { openBrowser, goto, link, click, closeBrowser } = require('taiko');

(async () => {
  await openBrowser();
  await goto('https://example.com');
  await click(link({ id: 'nav-home' }));
  await closeBrowser();
})();

Related Pages

Page Connections

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