Class KeyboardActions


  • public class KeyboardActions
    extends Object
    Execute actions with the keyboard.
    • Constructor Detail

      • KeyboardActions

        public KeyboardActions​(org.openqa.selenium.WebDriver driver)
        Creates a new object to execute actions with the keyboard, using given selenium driver.
        Parameters:
        driver - selenium driver
    • Method Detail

      • actions

        protected org.openqa.selenium.interactions.Actions actions()
        Get selenium interactions actions.
        Returns:
        selenium actions
      • keyDown

        public KeyboardActions keyDown​(org.openqa.selenium.Keys theKey)
        Performs a modifier key press. Does not release the modifier key - subsequent interactions may assume it's kept pressed. Note that the modifier key is never released implicitly - either keyUp(theKey) or sendKeys(Keys.NULL) must be called to release the modifier.
        Parameters:
        theKey - Either Keys.SHIFT, Keys.ALT or Keys.CONTROL. If the provided key is none of those, IllegalArgumentException is thrown.
        Returns:
        this object reference to chain calls
        See Also:
        Actions.keyDown(CharSequence)
      • keyUp

        public KeyboardActions keyUp​(org.openqa.selenium.Keys theKey)
        Performs a modifier key release. Releasing a non-depressed modifier key will yield undefined behaviour.
        Parameters:
        theKey - Either Keys.SHIFT, Keys.ALT or Keys.CONTROL.
        Returns:
        this object reference to chain calls
        See Also:
        Actions.keyUp(CharSequence)
      • sendKeys

        public KeyboardActions sendKeys​(CharSequence... keysToSend)
        Sends keys to the active element. This differs from calling WebElement.sendKeys(CharSequence...) on the active element in two ways:
        • The modifier keys included in this call are not released.
        • There is no attempt to re-focus the element - so sendKeys(Keys.TAB) for switching elements should work.
        Parameters:
        keysToSend - The keys.
        Returns:
        A self reference.
        See Also:
        Actions.sendKeys(CharSequence...)