Wednesday, October 29, 2014

Chapter 22- Keyboard Actions

Keyboard Actions

Sometimes we would be in a situation to input some key combinations. Eg - pressing ctrl key or Shift key. Below are the methods to interact with 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" or "Tab" or "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 is usually holds good for non text characters.
Below 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)

No comments: