mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-18 13:34:06 +01:00
25 lines
881 B
TypeScript
25 lines
881 B
TypeScript
import { Page, Locator } from '@playwright/test';
|
|
|
|
export const selectFirstOption = async (page: Page, triggerLocator: Locator) => {
|
|
let selected = false
|
|
while (!selected) {
|
|
try {
|
|
await triggerLocator.click({ force: true });
|
|
|
|
// Select the first available option
|
|
const firstOption = page.getByRole("option").first();
|
|
await firstOption.waitFor({ state: 'visible', timeout: 1000 });
|
|
|
|
// Retrieve and log the text content of the first option
|
|
const optionText = await firstOption.textContent();
|
|
console.log(`${optionText}`);
|
|
await firstOption.click();
|
|
console.log("Selected.");
|
|
selected = true
|
|
} catch (error) {
|
|
console.log("Retrying as the combobox disappeared.");
|
|
await page.waitForTimeout(100);
|
|
}
|
|
}
|
|
};
|