Skip to content

fix(node): focus instead of clicking an element send_keys types into - #386

Merged
route merged 1 commit into
mainfrom
fix/send-keys-focus
Nov 25, 2026
Merged

route merged 1 commit into
mainfrom
fix/send-keys-focus

Conversation

@route

@route route commented Nov 25, 2026

Copy link
Copy Markdown
Member

Node#send_keys clicked an element that didn't have focus before typing. This dates back to the initial commit. Three things went wrong:

  • checkbox.send_keys(:space) left the checkbox unchecked: the click checked it and the space unchecked it.
  • Sending any keys to a link fired its onclick, or followed it.
  • In a filled field, the keys went wherever the click put the caret, which is the middle of the field. .com sent to user@example gave user@exam.comple. The existing specs only used short values like "Text", so this never showed up.

What it does now, matching WebDriver:

  • _cuprite.focusForTyping is one JS call. It does nothing if the element already has focus or contains the selection, as before. Otherwise it calls focus() and puts the caret at the end: a collapsed range for contenteditable, setSelectionRange for inputs and textareas that support it.
  • Email and number inputs have no selection API, so it returns true and Ruby presses End. set(clear: :none) does the same since feat(node): support clear: in set and warn about unsupported options #378.
  • There's no mouse hit test any more, so a covered element still gets the keys.

Specs: three new ones under Node#send_keys (checkbox, link, filled email input). All three fail without the fix. node_spec and driver_spec pass (305 examples), and so do the related Capybara specs (send_keys, fill_in, :focused). CHANGELOG line under Fixed.

send_keys clicked an element that didn't have focus, so a checkbox toggled before a space toggled it back, a link was
followed, and the keys went where the click put the caret, the middle of a filled field. It now focuses the element and
puts the caret at the end, pressing End for email and number inputs, which have no selection API.
@route
route merged commit 7f1e305 into main Nov 25, 2026
6 checks passed
@route
route deleted the fix/send-keys-focus branch November 25, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant