microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.76k stars 3.58k forks source link

[BUG] Unable to iterate thru the locators #22999

Closed InduKrish closed 1 year ago

InduKrish commented 1 year ago

I want to iterate thru the table, and store the cell values to dataAfter constant. it doesnt print console.log- cells value at all. looks like the loop is not executing., want to use the table value (dataAfter) to compare with sorted array tableDataSortedAsc, to see if table values are in ascending order.

want to assert if the table values are in ascending order.

const tableDataSortedAsc = [ ['ATL'], ['AUS'], ['BWI'], ['DAL'], ['DEN'], ['FLL'] ]

  const dataAfter = await page.locator("[data-testid='table-IFOverview'] tbody tr", (rows) => {
                return rows.map(row => {
                    const cells = row.querySelectorAll('td');
                    console.log("cells" + cells.textContent())
                    return Array.from(cells).map(cell => cell.textContent);
                })
            });

            console.log("dataAfter"  + dataAfter)

output: dataAfterLocator@[data-testid='table-IFOverview'] tbody tr

I' m referring the link below, which uses elementHandles, i wanted to use Locator instead and iterate thru the table. Please advise if there are any other solution to verify the table values in ascending order.

https://applitools.com/event/verifying-sortable-tables-in-playwright-js/

Screen Shot 2023-05-12 at 1 07 58 PM
pavelfeldman commented 1 year ago

This does not look like a bug report or a feature request, try asking your question on discord!