Files
2025-08-30 13:46:35 -06:00

36 lines
882 B
TypeScript

import { Locator, Page } from "@playwright/test";
export async function findVisibleButton(
page: Page,
text: string,
): Promise<Locator> {
const buttons = page.locator(`button:has-text("${text}")`);
const buttonCount = await buttons.count();
for (let i = 0; i < buttonCount; i++) {
const button = buttons.nth(i);
if (await button.isVisible()) {
return button;
}
}
throw new Error(`No visible button with text "${text}" found`);
}
export async function findVisibleElement(
page: Page,
selector: string,
): Promise<Locator> {
const elements = page.locator(selector);
const elementCount = await elements.count();
for (let i = 0; i < elementCount; i++) {
const element = elements.nth(i);
if (await element.isVisible()) {
return element;
}
}
throw new Error(`No visible element with selector "${selector}" found`);
}