Resolve a form field by label → placeholder → role=textbox → [name]/#id.
Uses Playwright's ready-made semantic locators (getByLabel, getByPlaceholder,
getByRole) with .or() fallbacks — matches the accessibility-first lookup
chain recommended by https://playwright.dev/docs/locators.
/
function resolveField(page, field) {
return page.getByLabel(field).or(
page.getByPlaceholder(field)
).or(
page.getByRole('textbox', { name: field })
).or(
page.locator([name="${field}"], #${field})
).first();
}
/**
Move keyboard focus to a field by label, name, or id.
Step pattern
When (I |we )*move focus to "([^"]*)" fieldExamples
Example #1
When I move focus to "Title" fieldExample #2
When I move focus to "Body" fieldExample #3
When I move focus to "Email" fieldExample #4
When I move focus to "Search" fieldExample #5
When I move focus to "Username" fieldExample #6
When I move focus to "Password" fieldExample #7
When I move focus to "First name" fieldExample #8
When I move focus to "Last name" fieldExample #9
When I move focus to "Description" fieldExample #10
When I move focus to "Phone" field