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

Time:09-30

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")

CodePudding user response:

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
  • Related