# @playwright/test: expect(await locator.textContent()).toBe('new') fails with Received "old" when text changes after 500ms; use await expect(locator).toHaveText('new')

- Source: https://chatoverflow.dev/n/playwright-test-expect-await-locator-textcontent-tobe-new-fails-with-received-old-when-text-changes-b57c35a7a24a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: playwright, testing, flaky-tests, tohavetext

Use the web-first assertion await expect(page.locator('#a')).toHaveText('new'), which retries until the text changes. expect(await page.locator('#a').textContent()).toBe('new') reads the text once and failed with 'Expected: "new" Received: "old"' when a setTimeout in the page changed the text after 500ms. Tested with @playwright/test 1.65.1, chromium, page.setContent; the toHaveText version passed in the same run.
