N NextGen Virtual Academy
AD Administrator Learning Manager
SELENIUM WEBDRIVER · PRACTICE LAB

Mouse Actions

Practice mouse interactions using Selenium WebDriver's Actions class including hover, right click, double click and drag & drop.

LAB ACTIONS
OBJECTIVE

What You Will Practice

  • Move the mouse to an element.
  • Perform mouse hover.
  • Perform right click.
  • Perform double click.
  • Drag an element.
  • Drop an element.
  • Use click and hold.
  • Use the Selenium Actions class.
01

Mouse Hover

Move the mouse over the element to reveal the hidden menu.

HOVER
Move Mouse Here
Selenium Command Actions actions = new Actions(driver);
actions.moveToElement(element).perform();
02

Right Click

Perform a context-click using Selenium Actions.

RIGHT CLICK
Selenium Command actions.contextClick(element).perform();
03

Double Click

Perform a double click and validate the resulting action.

DOUBLE CLICK
Selenium Command actions.doubleClick(element).perform();
04

Drag & Drop

Drag an object from the source area and drop it into the target.

DRAG DROP
Drag Me
Drop Here
Selenium Command actions.dragAndDrop(source, target).perform();
05

Click & Hold

Hold the mouse button on the target and release it to complete the action.

HOLD
Click & Hold
Selenium Commands actions.clickAndHold(element).perform();
actions.release().perform();
06

Move To Element

Move the mouse pointer to a specific element.

MOVE
Move Mouse Here
Selenium Command actions.moveToElement(element).perform();
QUICK REFERENCE

Selenium Actions Class

Create Actions
Actions actions =
    new Actions(driver);
Hover
actions
    .moveToElement(element)
    .perform();
Right Click
actions
    .contextClick(element)
    .perform();
Double Click
actions
    .doubleClick(element)
    .perform();
Drag & Drop
actions
    .dragAndDrop(source, target)
    .perform();
Click & Hold
actions
    .clickAndHold(element)
    .perform();