Selenium - Keyboard Actions

Given below are the methods to perform keyboard actions −

  • sendKeys − Sends keys to the keyboard representation in the browser. Special keys that are not text, represented as Keys are recognized both as part of sequences of characters, or individually.

  • pressKey − Press a key on the keyboard that is NOT text. The keys such as function keys "F1", "F2", "Tab", "Control", etc. If keyToPress is a sequence of characters, different driver implementations may choose to throw an exception or to read only the first character in the sequence.

  • releaseKey − Release a key on the keyboard after executing the keypress event. It usually holds good for non text characters.

Here are the syntax to call keyboard functions using Selenium WebDriver.

void sendKeys(java.lang.CharSequence keysToSend)
void pressKey(java.lang.CharSequence keyToPress)
void releaseKey(java.lang.CharSequence keyToRelease)