Repository navigation
Description
Use case
Many forms run their validation, formatting or onchange logic only when a field loses focus. After Fill Text the field typically still has focus, so that logic never fires and assertions on validation messages fail. The library has a Focus keyword but no counterpart to remove focus; today users must fall back to Evaluate JavaScript selector (e) => e.blur(). That works: it resolves the selector with strict mode and waits for the element, so Blur adds no new capability. The keyword exists so that users do not need JavaScript for a generally useful need. Playwright provides locator.blur for exactly this.
Proposed keyword / arguments
Blur selector
selector— element to blur (auto-waits, strict-mode resolved, supports>>>frame piercing likeFocus). Required.
There is no timeout argument. Like Focus and other keywords that interact with elements, Blur uses the library timeout, which Set Browser Timeout changes.
If the element does not have focus, the keyword does nothing and passes, and no blur event is fired. Use Get Element States to verify the state.
Blur css=:focus removes focus from the focused element in the main frame, outside shadow DOM. Inside an iframe or a shadow DOM, use a selector of the element itself. If nothing has focus, the selector matches nothing and the keyword fails after the timeout.
Fill Text id=email not-an-email
Blur id=email
Get Text css=.validation-error == Please enter a valid email address
Focus id=search
Blur id=search
Get Element States id=search contains defocusedPlaywright API
Implementation notes
- New
rpc Blur(Request.ElementSelector)inprotobuf/playwright.proto, reusing the request used byFocus. - One-line locator call in
node/playwright-wrapper/interaction.ts. - Python keyword next to
focusinBrowser/keywords/interaction.py, with docs. - Acceptance tests in
atest/test/02_Content_Keywords/focus.robot: focus is removed, theblurevent fires, an element without focus does nothing and leaves focus on the other element,css=:focus, and strict mode on and off. They assert theblurevent rather thanonchange, becausebluris what the keyword directly causes.
Implemented in #5422.
Backwards compatibility
Purely additive: a new keyword complementing the existing Focus; no existing behavior changes.
Activity
feat: add Blur keyword