Skip to content

Add Blur keyword to remove focus from an element #5102

Description

@Snooz82

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 like Focus). 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    defocused

Playwright API

locator.blur

Implementation notes

  • New rpc Blur(Request.ElementSelector) in protobuf/playwright.proto, reusing the request used by Focus.
  • One-line locator call in node/playwright-wrapper/interaction.ts.
  • Python keyword next to focus in Browser/keywords/interaction.py, with docs.
  • Acceptance tests in atest/test/02_Content_Keywords/focus.robot: focus is removed, the blur event fires, an element without focus does nothing and leaves focus on the other element, css=:focus, and strict mode on and off. They assert the blur event rather than onchange, because blur is what the keyword directly causes.

Implemented in #5422.

Backwards compatibility

Purely additive: a new keyword complementing the existing Focus; no existing behavior changes.

Activity

  1. self-assigned this
    on Aug 6, 2026
  2. added theissue type on Aug 6, 2026
  3. added this to the Ecosystem project milestone on Sep 26, 2026
  4. assigned and unassigned on Nov 1, 2026
  5. added a commit that references this issue on Nov 1, 2026
    e90eb93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions