Skip to content

[Feature] Playwright API for checking 'text contains' in array of elements  #8869

@AlexKomanov

Description

@AlexKomanov

Hi all,

I want to check if some row within a table (array of rows) contains some text.
If I use the expect API - it will fail on the first not matching result.
I created a custom method as can be seen below and I use a regular JS forEach() function. Is any other solution that I missed? Orr if there is no one - is it possible to create it?

   public async validateItemOnGrid(item: string) {
        await this.searchWithQuickSearchField(item);
        const gridRows = await this.page.$$('[data-uitestingname="body.Grid"] [data-uitestingname^="body.Grid.Row."] >> visible=true');
        for (let gridRow of gridRows) {
            const rowText = await gridRow.innerText();
            console.log(rowText);
            if (rowText.includes(item)) {
                await gridRow.click();
                await this.validator.validateContainText(rowText, item)
                return;
            }
        }
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions