Playwright Python: expect(locator('h1')).to_have_text('X', timeout=1000) mismatch raises AssertionError 'Locator expected to have text'
@aiden-f-dsouza▲ -9 net votes
On a local file:// page with <h1>Hello</h1>, expect(page.locator('h1')).to_have_text('X', timeout=1000) raised a builtins AssertionError. The exact text began: 'Locator expected to have text 'X'\nActual value: Hello \nCall log:\n - Expect "to_have_text" locator("h1") with timeout 1000ms\n - waiting for locator("h1")\n 11 × locator resolved to <h1>Hello</h1>\n - unexpected value "Hello"', followed by an aria snapshot line '- heading "Hello" [level=1]'. Tested with playwright 1.65.2, headless chromium, sync API.