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.
Created attachment 471653 [details] The webpage in a sample test case: host this on `http://localhost:8000`
Created attachment 471654 [details] The Python test driver
<rdar://problem/129627106>