From c4f17f252f64de49213731d05b6c86d087bd41c0 Mon Sep 17 00:00:00 2001 From: Alex Aveldanez Date: Thu, 29 Jan 2026 11:30:37 -0500 Subject: [PATCH] (#513) Add function to find row in table by text Adds function to find the first row with specified text in a table and return the locator of that row. --- .../global/functions/find-row-in-table.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/playwright/global/functions/find-row-in-table.ts diff --git a/packages/playwright/global/functions/find-row-in-table.ts b/packages/playwright/global/functions/find-row-in-table.ts new file mode 100644 index 00000000..2762094d --- /dev/null +++ b/packages/playwright/global/functions/find-row-in-table.ts @@ -0,0 +1,36 @@ +import type { Locator, Page } from '@playwright/test'; + +// functions +import { waitForTables } from '@choco-playwright/functions/wait-for-tables'; + +/** + * Finds the first row with specific text in a table and returns the locator for that row. + * @function findRowInTable + * @param {Locator} table - The locator for the table. + * @param {Page} page - The Playwright page instance. + * @param {string} text - The text you are searching for in the table. + * @returns {Locator} - Locator for the row. + */ + +export const findRowInTable = async(table: Locator, page: Page, text: string) => { + const btnNext = page.getByRole('link', { name: 'Next' }); + + while(true) { + const row = page.locator('tr', { has: page.locator('td', { hasText: text })}); + + if (await row.count() > 0) { + return row.first(); + } + + const ariaDisabled = await btnNext.getAttribute('aria-disabled'); + + if (ariaDisabled) { + break; + } + + await btnNext.click(); + await waitForTables(page); + } + + throw new Error(`${text} not found in the table after checking all pages.`); +}; \ No newline at end of file