Reputation: 1363
I was wondering if it is possible to press a key with Java. Not quite sure how to approach this. There must be some type of class that has like sendKeyPress(); or something.
Upvotes: 15
Views: 52769
Reputation: 1
Action act = new Action(driver);
act.sendkeys(Keys.ENTER).build().perform();
Upvotes: 0
Reputation: 38424
You can do it easily with the Robot
class. That just virtually presses the button, with no special targeting or anything.
For example, to press Enter:
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
Upvotes: 23