Sending Key Up in Selenium

I have a text input with a handler attached to the keyup event. The problem was that the Selenium send_keys method does not send a keyup event when it completes. There is no special Key for that. For example Key.Up does not solve the problem.

Action Chains has key_up and key_down methods. The problem is they are designed to be used with modifier keys, such as Control. It turns out you can get a keyup event by a key_down immediately followed by a key_up, like this:

ActionChains(driver).move_to_element(element).send_keys('sometext').\
    key_down(Keys.CONTROL).key_up(Keys.CONTROL).perform()

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s