Bug 275375 - [WebDriver] keyup events are not delivered when any modifier key is involved
Summary: [WebDriver] keyup events are not delivered when any modifier key is involved
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebDriver (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-06-11 15:24 PDT by Qianlang Chen
Modified: 2024-06-18 23:27 PDT (History)
5 users (show)

See Also:


Attachments
The webpage in a sample test case: host this on `http://localhost:8000` (752 bytes, text/html)
2024-06-11 15:25 PDT, Qianlang Chen
no flags Details
The Python test driver (348 bytes, text/x-python-script)
2024-06-11 15:26 PDT, Qianlang Chen
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Qianlang Chen 2024-06-11 15:24:14 PDT
Suppose we start with this Python 3 code (with Selenium 4 installed):

    import time
    from selenium.webdriver import Safari, Keys
    driver = Safari()
    driver.get(".../some/webpage.html")
    time.sleep(2)

If we do

    driver.find_element("tag name", "body").send_keys("abc")  # Case 1

Then, for each of the keys A, B, and C, a `keydown` even is sent and a `keyup` event immediately follows. This is correct and is what happens even if the browser window loses input focus.

However, if we do

    driver.find_element("tag name", "body").send_keys(Keys.COMMAND, "a")

Then,

   - If the browser window is focused, a `keydown` for Command is sent and a `keydown` event for A are sent. No `keyup` events are sent at all. (Case 2)

   - If the browser window is NOT focused, a `keydown` for Command is sent, and that's it. (Case 3)

If we log in the target webpage details of the events it receives, this is what we see:

   - Case 1:
       {"type":"keydown","key":"a","metaKey":false}
       {"type":"keyup","key":"a","metaKey":false}
       {"type":"keydown","key":"b","metaKey":false}
       {"type":"keyup","key":"b","metaKey":false}
       {"type":"keydown","key":"c","metaKey":false}
       {"type":"keyup","key":"c","metaKey":false}

   - Case 2:
       {"type":"keydown","key":"Meta","metaKey":true}
       {"type":"keydown","key":"a","metaKey":true}

   - Case 3:
       {"type":"keydown","key":"Meta","metaKey":true}

Case 1 is correct. The correct log for both Case 2 and Case 3 should be:
       {"type":"keydown","key":"Meta","metaKey":true}
       {"type":"keydown","key":"a","metaKey":true}
       {"type":"keyup","key":"a","metaKey":true}
       {"type":"keyup","key":"Meta","metaKey":false}

And this is the output of Chrome/chromedriver, regardless of whether the window is focused.
Comment 1 Qianlang Chen 2024-06-11 15:25:22 PDT
Created attachment 471653 [details]
The webpage in a sample test case: host this on `http://localhost:8000`
Comment 2 Qianlang Chen 2024-06-11 15:26:03 PDT
Created attachment 471654 [details]
The Python test driver
Comment 3 Radar WebKit Bug Importer 2024-06-11 15:26:19 PDT
<rdar://problem/129627106>