Skip to content

send_keys: skip click if Node has focus - #327

Open
seanpdoyle wants to merge 1 commit into
rubycdp:mainfrom
seanpdoyle:send-keys-active-element
Open

seanpdoyle wants to merge 1 commit into
rubycdp:mainfrom
seanpdoyle:send-keys-active-element

Conversation

@seanpdoyle

Copy link
Copy Markdown
Contributor

The current Capybara::Cuprite::Page#send_keys implementation attempts to trigger a click on the specified node argument.

This commit aims to avoid that click if the element already has focus. For example, if no element has focus, it is possible for the document.body element to serve as the focus fallback.

After this change, a bare send_keys will not attempt to click on the document.body element, but will still trigger the keystrokes.

The current `Capybara::Cuprite::Page#send_keys` implementation attempts
to trigger a `click` on the specified `node` argument.

This commit aims to avoid that click if the element already has focus.
For example, if _no_ element has focus, it is possible for the
`document.body` element to serve as the focus fallback.

After this change, a bare `send_keys` will not attempt to click on the
`document.body` element, but will still trigger the keystrokes.
@seanpdoyle
seanpdoyle force-pushed the send-keys-active-element branch from 2253643 to dce6322 Compare September 11, 2026 15:11

def send_keys(node, keys)
unless evaluate_on(node: node, expression: %(_cuprite.containsSelection(this)))
unless evaluate_on(node: node, expression: %(_cuprite.containsSelection(this) || _cuprite.hasFocus(this)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@route are you able to provide review for this change?

I'm happy to explore something more ad hoc if introducing a "public" hasFocus JavaScript method is undesirable.

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