Skip to content
CodeKruPro

getByLabel and getByPlaceholder

10/70

getByLabel and getByPlaceholder

Playwright provides user-centric locators that find elements the way a real user would:

  • page.getByPlaceholder(text) — finds inputs by their placeholder text
  • page.getByLabel(text) — finds inputs by their associated label

locator.fill('text') types into an input (it clears the field first). Read the live value with locator.inputValue(), and the id with getAttribute('id').

On the Text Fields page, there is a field with placeholder Enter your last name....

Task:

  1. Navigate to https://testkru.com/Elements/TextFields
  2. Find the field by its placeholder text with getByPlaceholder()
  3. Print its ID, read with getAttribute()
  4. Type "Playwright" into the field using fill()
  5. Print the field's current value using inputValue()

Expected output:

Field ID: lastNameWithPlaceholder
Typed value: Playwright