[Question] Is `count` on Locator working as expected?
See original GitHub issueSo I have a locator for this selector here like this
const foo = '.tab-content table#outer-table > tbody > tr:not(#inner-table-row) > td'
const el = await page.locator(foo).count()
console.log(el)
I wanted to do an assertion on the number of elements retrieved, so count()
seemed appropriate. However when I log out the count
I see 0 and this warning
Uncaught exception: Error: strict mode violation: ".tab-content table#outer-table > tbody > tr:not(#inner-table-row) > td" resolved to 50 elements:
So the selector resolved to 50 elements:
, yet the count of those elements is 0?
How can that be?
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
[Question] Is the locator.count() function supposed to wait for ...
The original code I was using was: const numberOfDresses: number = await this.page.locator(DressesPage.dressesPrices).count();.
Read more >Powershell .count function not working as expected
I find that if I declare the array as an empty array and then add items to it (+=)instead of assigning a result...
Read more >COUNT and COUNTA functions to count cells in Excel - Ablebits
This short tutorial explains the basics of the Excel COUNT and COUNTA functions and shows a few examples of using a count formula...
Read more >Telework and Remote Work Frequently Asked Questions
If an employee is authorized to work remotely from one location, can they work remotely from a different location? An employee's pay is...
Read more >Inventory Cycle Counting 101: Best Practices & Benefits
Cycle counting is a method of checks and balances by which companies ... Counters should review the inventory locations, descriptions, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vomc the rule of thumb is to always prefer web-first assertions!
To assert count, you should use
expect(locator).toHaveCount(50)
Ah! yes that works, thank you @ltsuda ! To me as a beginner in Playwright this was not obvious from the documentation. Since it returns a Promise, I assumed that it would get the total count once the page is loaded.