← Back to library
Playwrightassertionsintermediatev1.20+

Get all text from a list of elements

Collect every matched element's text into a string array and assert the collection.

1test('blog tags include "playwright"', async ({ page }) => {
2  await page.goto('/blog');
3
4  const tags = page.locator('[data-testid="tag"]');
5
6  // allTextContents() resolves the full locator set to a string[]
7  const texts = await tags.allTextContents();
8
9  expect(texts.length).toBeGreaterThan(0);
10  expect(texts).toContain('playwright');
11
12  // Assert no duplicate tags
13  const unique = new Set(texts);
14  expect(unique.size).toBe(texts.length);
15});
#allTextContents#text#list#array