Anonymous
Anonymous

Reputation: 13

How to simulate the up key using the keyboard module in python?

I am using the keyboard module on python to input text using Selenium. I am trying to simulate shift + up_key to highlight and delete text but I am not familiar with the keycodes in python. I am using macOS to simulate the keypresses.

    if current_url == TARGET_URL:
        print("success!")
    else:
        #up_key not being a valid keystroke
        keyboard.send("shift+up_key")
        keyboard.send("delete")

Upvotes: 1

Views: 514

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

If you have a WebElement, let's say element, you can do following :

element.send_keys(Keys.LEFT_SHIFT).send_keys(Keys.ARROW_UP)

or

element.send_keys(Keys.LEFT_SHIFT, Keys.ARROW_UP)

import would be :

from selenium.webdriver.common.keys import Keys

Upvotes: 2

Related Questions