Skip to content

send_keys enhancement #155

Merged
stephanlensky merged 35 commits into
cdpdriver:mainfrom
hvgupta:main
Jul 17, 2025
Merged

send_keys enhancement #155
stephanlensky merged 35 commits into
cdpdriver:mainfrom
hvgupta:main

Conversation

@hvgupta
Copy link
Copy Markdown
Contributor

@hvgupta hvgupta commented Jul 9, 2025

Description

tldr: Refactored keyboard input with new KeyEvents system, adding modifier and special key support, improved event handling, and fully backwards compatible.

  • Complete rewrite of keyboard input system with new KeyEvents class in zendriver.core.keys
  • Added support for modifiers (Ctrl, Alt, Shift, Meta)
  • Added support for special keys including arrows, escape, delete and backspace
  • Added KeyEvents.from_text() class method for converting plain text to cdp events
  • Added KeyEvents.from_mixed_input() class method for handling mixed sequences of text, special keys to cdp events
  • Comprehensive key event types: CHAR, KEY_DOWN, KEY_UP
  • Added key event type (DOWN_AND_UP) as a combination of KEY_DOWN and KEY_UP
  • Element.send_keys() now uses the new KeyEvents system (it is still backwards compatible with passing a string)
  • Key event processing now properly handles modifier key sequences

Pre-merge Checklist

  • I have described my change in the section above.
  • I have ran the ./scripts/format.sh and ./scripts/lint.sh scripts. My code is properly formatted and has no linting errors.
  • I have added my change to CHANGELOG.md under the [Unreleased] section.

@hvgupta hvgupta requested a review from stephanlensky as a code owner July 9, 2025 01:56
@nathanfallet
Copy link
Copy Markdown
Member

Hello, thanks for your contribution!
I'll take a look, it's quite a big PR

Copy link
Copy Markdown
Member

@nathanfallet nathanfallet left a comment

Choose a reason for hiding this comment

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

That's a lot of changes, especially with the new keys.py file which introduces complexe logic. I think we should add tests to cover the common cases (for the send_keys method of the Tab class, and also most of the complex logic inside of the KeyEvents class. That would make sure everything works as expected, and stays correct in the future (and sometimes they allow us to find hidden bugs)

Comment thread tests/keys/test_keyinputs.py Outdated
@nathanfallet
Copy link
Copy Markdown
Member

LGTM 👍
Just need to fix lint (with the ./scripts/format.sh and ./scripts/lint.sh scripts)

nathanfallet
nathanfallet previously approved these changes Jul 16, 2025
nathanfallet
nathanfallet previously approved these changes Jul 16, 2025
stephanlensky
stephanlensky previously approved these changes Jul 17, 2025
Copy link
Copy Markdown
Member

@stephanlensky stephanlensky left a comment

Choose a reason for hiding this comment

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

This looks really good! Thank you for the contribution. Just one question about the changelog and then a tiny nit for the code, then I'll get this merged and released for you.

Comment thread CHANGELOG.md Outdated
Comment thread CHANGELOG.md Outdated
from zendriver import SpecialKeys, KeyModifiers, KeyEvents


async def test_visible_events(browser: zd.Browser):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for adding tests!

Comment thread zendriver/core/element.py Outdated
Co-authored-by: Stephan Lensky <8302875+stephanlensky@users.noreply.github.com>
@hvgupta hvgupta dismissed stale reviews from stephanlensky and nathanfallet via cccca34 July 17, 2025 01:44
hvgupta and others added 3 commits July 17, 2025 09:45
Co-authored-by: Stephan Lensky <8302875+stephanlensky@users.noreply.github.com>
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.

4 participants