Playwright · Junior · Question 68 of 75
Which assertion checks an element's attribute?
- 1
await expect(link).toHaveAttribute('href', '/docs') - 2
await expect(link).toHaveProp('href', '/docs') - 3
await expect(link.href).toBe('/docs')
Show the answer
Correct answer: await expect(link).toHaveAttribute('href', '/docs')
Explanation
toHaveAttribute reads the DOM attribute with retries. toHaveJSProperty checks a JavaScript property instead.