-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
Problem
There is a certain confusion between send keys in actions vs element. Both allow to be used to simulate key chords (e.g. pressing a character key with a modifier key) but the behavior is very much different.
- Calling send keys on the element with a key chord gives a character printed with the modifier key pressed
- Calling send_keys on the actions with a key chord gives a character printed without the modifier key pressed
Should make the behave similar to avoid user confusion and work like OSS dialect used to (it didn't have this problem)?
Root cause
The problem is in the way actions sendKeys construct keyDown/keyUp events. It doesn't differentiate between modifier and character keys, so it simply generates a pair of keyDown/keyUp events for every key.
For example, if we wanted to press shift and a using actions sendKeys, it would generate the following events:
- key down shift
- key up shift
- key down a
- key up a
If we would like to make actions sendKeys work similar to element sendKeys, it should generate the events in a different order:
- key down shift
- key down a
- key up a
- key up shift
Sample Code
Here is a sample code using http://the-internet.herokuapp.com/inputs and tested in Chrome/Firefox:
Python
driver.find_element_by_tag_name('input').send_keys(Keys.SHIFT, 'a')
# types "A" to the input
driver.find_element_by_tag_name('input').click()
ActionChains(browser).send_keys(Keys.SHIFT, 'a').perform()
# types "a" to the inputRuby
driver.find_element(tag_name: 'input').send_keys([:shift, 'a'])
# types "A" to the input
driver.find_element(tag_name: 'input').click
driver.action.send_keys([:shift, 'a']).perform
# types "a" to the input