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 textpage.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:
- Navigate to
https://testkru.com/Elements/TextFields - Find the field by its placeholder text with
getByPlaceholder() - Print its ID, read with
getAttribute() - Type "Playwright" into the field using
fill() - Print the field's current value using
inputValue()
Expected output:
Field ID: lastNameWithPlaceholder Typed value: Playwright
TestKru