Implementation:Getgauge Taiko TableCellWrapper
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Element_Selection |
| Last Updated | 2026-02-12 03:00 GMT |
Overview
Concrete tool for selecting HTML table cell (``) elements by row/column index and optional table identifier provided by the Taiko browser automation library.
Description
`TableCellWrapper` is a specialized subclass of `ElementWrapper` that locates HTML `` (table data) elements within tables. At 59 lines, it is more complex than most wrappers because it must handle the structural nuances of HTML tables, including the semantic ordering of `<tbody>` and `<tfoot>` sections.
The class provides two core mechanisms:
`tableXPathFn(tableXPath)` -- An internal XPath builder method that, given a base table XPath expression, generates and concatenates three XPath queries to locate cells:
- Direct `tr` children of the table: `{tableXPath}/tr[td][row]/td[col]`
- Rows inside `<tbody>`: `{tableXPath}/tbody/tr[td][row]/td[col]`
- Rows inside `<tfoot>`: `{tableXPath}/tfoot/tr[td][row - count(../../tbody/tr[td])]/td[col]`
The `<tfoot>` query adjusts the row index by subtracting the number of `<tbody>` rows, because although `<tfoot>` may appear before `<tbody>` in the HTML source, browsers render it after `<tbody>`.
`_get()` -- The element retrieval method operates in two modes:
- Row/column only mode -- When no label or attribute-value pairs are provided, the method requires both `row` and `col` options and searches across all tables on the page (`//table`).
- Table identifier mode -- When a label is provided, it uses `getElementGetter()` to build an XPath that matches tables by `id` attribute, `` text, or `` header text (case-insensitive). The row/column options select the specific cell within the matched table.
Usage
Use `TableCellWrapper` (via the `tableCell()` selector in Taiko) when you need to read or interact with specific cells in an HTML table. This is the appropriate selector when you know the row and column indices of the target cell, and optionally the table's identity via its id attribute, caption, or header text.
Code Reference
Source Location
- Repository: Getgauge_Taiko
- File: lib/elementWrapper/tableCellWrapper.js
- Lines: 1-59
Signature
class TableCellWrapper extends ElementWrapper {
constructor(query, attrValuePairs, _options, ...args) {
super('Table', query, attrValuePairs, _options, ...args);
this.tableXPathFn = async (tableXPath) => {
// Concatenates XPath results from: direct tr, tbody/tr, tfoot/tr
};
this._get = async () => {
// Mode 1: row/col only -- searches all tables
// Mode 2: table identifier -- matches by id, caption, or header text
};
}
}
Import
const { tableCell } = require('taiko');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| query | string | Yes | The query type passed to the parent constructor (internally set to the query property name). |
| attrValuePairs | string / Object | No | A table identifier string matched against the table's `id` attribute, ` |
| ` header text (case-insensitive). Can also be an attribute-value pair object. When omitted, all tables on the page are searched. | |||
| _options | Object | Yes | Options object that must include `row` (number) and `col` (number) properties specifying the 1-based row and column indices of the target cell. |
| ...args | RelativeSearchElement[] | No | Zero or more relative search elements for proximity-based filtering. |
Outputs
| Name | Type | Description | |
|---|---|---|---|
| TableCellWrapper | TableCellWrapper | An `ElementWrapper` instance representing all matched ` | ` elements. Delegates to the first match for actions like `click()`, `exists()`, and `text()`. |
Usage Examples
Basic Usage -- Row and Column Only
const { openBrowser, goto, tableCell, closeBrowser } = require('taiko');
(async () => {
await openBrowser();
await goto('https://example.com/report');
const cellText = await tableCell({ row: 2, col: 3 }).text();
console.log('Cell value:', cellText);
await closeBrowser();
})();
With Table Identifier
const { openBrowser, goto, tableCell, closeBrowser } = require('taiko');
(async () => {
await openBrowser();
await goto('https://example.com/report');
// Match table by caption text, then select row 1, column 2
const cellText = await tableCell({ row: 1, col: 2 }, 'Quarterly Revenue').text();
console.log('Revenue cell:', cellText);
await closeBrowser();
})();
Existence Check
const { openBrowser, goto, tableCell, closeBrowser } = require('taiko');
(async () => {
await openBrowser();
await goto('https://example.com/report');
const exists = await tableCell({ row: 5, col: 1 }).exists();
console.log('Cell exists:', exists);
await closeBrowser();
})();