2

I'm trying to write a keyDown and keyUp for webdriver, similar to selenium. I know how to use Actions, but dint find a way to write a generic(working for special and normal keys) keyDown function.

Something like selenium which accepts keycode as well keys. Any ideas?

3 Answers 3

7

If you are trying to, for example, to select all from a input field and Delete, you can do something like this:

Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).sendKeys(Keys.DELETE).perform(); 
Sign up to request clarification or add additional context in comments.

Comments

1

Look at the JavaDoc for KeyUpAction and KeyDownAction in org.openqa.selenium.interactions:

Moved to GitHub:

See also:

2 Comments

Link is broken :-/
I think broken links are one of the main reasons why answers are supposed to include actual steps instead of simply posting a link.
0

KeyDown and KeyUp -- Used to press a key and then un press the key. Like below we can use this scenario;

Actions ac  = Actions(driverObj);
ac.keyDown(Keys.CONTROL).click(we).keyUp(Keys.CONTROL).build().perform();

Here we are using press CONTROL key and then click() and then unpress the CONTROL key.

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.