Learning keyboard-based interactions
Until now, we have seen all the actions that can be taken using a mouse. Now it's time to look at some of the actions that are specific to the keyboard in the Actions
class. Basically, there are three different actions that are available in the Actions
class that are specific to the keyboard. They are the keyUp
, keyDown
, and sendKeys
actions, each having two overloaded methods. One method is to execute the action directly on the WebElement, and the other is to just execute the method irrespective of its context.
The keyDown and keyUp actions
The keyDown()
method is used to simulate the action of pressing and holding a key. The keys that we are referencing here are the Shift, Ctrl, and Alt keys. The keyUp()
method is used to release the key that is already pressed using the keyDown()
method. The API syntax for the keyDown()
method is as follows:
public Actions keyDown(Keys theKey) throws IllegalArgumentException
An IllegalArgumentException
is thrown when the...