1

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.