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?

questions
  • 2,297
  • 4
  • 22
  • 37

3 Answers3

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(); 
bluish
  • 24,718
  • 26
  • 114
  • 174
Maria Lingo
  • 131
  • 1
  • 3
2

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

Moved to GitHub:

See also:

Community
  • 1
  • 1
paulsm4
  • 107,438
  • 16
  • 129
  • 179
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.

cruisepandey
  • 26,802
  • 6
  • 16
  • 37
Ankit Gupta
  • 737
  • 5
  • 12