INNER CODE UNIT · TypeScript

forEachMatch

pegaltier/awesome-utils-dev · utils-script/playwright-snippets.ts:4

async function forEachMatch<T>(locator: Locator, action: (currentLocator: Locator) => Promise<T>): Promise<T[]> {
    // Get the count of all the elements
    let locatorCount = await locator.count();

    // Prepare our list of return results
    let results: T[] = [];

    // Iterate through the elements
    for (let i = 0; i < locatorCount; i++) {
        
        // Get the current element using our index
        let currentLocator = locator.nth(i);

        // Run the user-given action for the current element
        let result = await action(currentLocator);

        // Store the result
        results.push(result);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…