WHICH ARE THE ACTIONS AVAILABLE IN ADVANCED USER INTERACTIONS API OF SELENIUM WEBDRIVER?

Actions: The Advanced User Interactions API includes following keyboard and mouse actions:

Keyboard Actions:
  • KeyDownAction - Holding down a modifier key.
  • KeyUpAction - Releasing a modifier key.
  • SendKeysAction - Equivalent to sendKeys() to type keyboard inputs.

Here is a code snippet to perform above keyboard action using action class:

new Actions(driver)
         .keyDown(Keys.SHIFT)
         .sendKeys("hello selenium")
         .keyUp(Keys.SHIFT)
         .build()
         .perform();

Detailed explanation for the above program is as follows:



Following code is to perform KeyDownAction to hold shift key.
keyDown(Keys.SHIFT)
Following code is to perform SendKeysAction to type hello selenium.
sendKeys("hello selenium")
Following code is to perform KeyUpAction to release shift key.
keyUp(Keys.SHIFT)





Mouse Actions:
  • MoveToElementAction - Moving the mouse from its current location to another element.
  • ClickAction - Equivalent to click() to perform mouse click operation.
  • DoubleClickAction - double-clicking an element.
  • MoveToOffsetAction - Moving the mouse to an offset from an element (The offset could be negative and the element could be the same element that the mouse has just moved to).
  • ClickAndHoldAction - Holding down the left mouse button.
  • ButtonReleaseAction - Releasing a held mouse button.
  • ContextClickAction - Clicking the mouse button that (usually) brings up the contextual (right click) menu.
  • DragAndDropAction - Drag and drop an element to another another.

Here is a code snippet to perform some of above mouse action using action class:

new Actions(driver)
       .moveToElement(someWebElement)
       .build()
       .perform();

new Actions(driver)
       .click(someWebElement)
       .build()
       .perform();

new Actions(driver)
       .doubleClick(someWebElement)
       .build()
       .perform();

new Actions(driver)
       .clickAndHold(someWebElement)
       .release(someWebElement)
       .build()
       .perform();

new Actions(driver)
       .contextClick(someWebElement)
       .build()
       .perform();

new Actions(driver)
       .dragAndDrop(someSourceWebElement, someTargetWebElement)
       .build()
       .perform();

Detailed explanation for the above program is as follows:



Following code is to perform MoveToElementAction to move mouse to the target element.
moveToElement(someWebElement)
Following code is to perform ClickAction to click on target element.
click(someWebElement)
Following code is to perform DoubleClickAction to double click on target element.
click(someWebElement)
Following code is to perform ClickAndHoldAction to target element.
clickAndHold(someWebElement)
Following code is to perform ButtonReleaseAction to target element.
release(someWebElement)
Following code is to perform ContextClickAction to target element.
contextClick(someWebElement)
Following code is to perform DragAndDropAction from source element to target element.
dragAndDrop(someSourceWebElement, someTargetWebElement)

build() and perform() must required to perform a action.



Post a Comment

0 Comments