Skip to content
CodeKruPro

expect - toHaveAttribute

37/70

Playwright Assertions: toHaveAttribute

await expect(locator).toHaveAttribute(name, value) asserts an HTML attribute's value.

Task:

  1. Navigate to https://testkru.com/Elements/TextFields
  2. Assert the last name field has attribute placeholder with value "Enter your last name..."
  3. Assert the disabled field has attribute disabled with value ""
  4. Print confirmation after each

Expected output:

Placeholder assertion: PASS
Disabled assertion: PASS