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,337
  • 4
  • 24
  • 39

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
  • 26,356
  • 27
  • 122
  • 180
Maria Lingo
  • 131
  • 1
  • 3
1

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

Moved to GitHub:

See also:

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
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
  • 28,520
  • 6
  • 20
  • 38
Ankit Gupta
  • 776
  • 5
  • 12