Mouse Actions
Practice mouse interactions using Selenium WebDriver's Actions class including hover, right click, double click and drag & drop.
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.
Mouse Hover
Move the mouse over the element to reveal the hidden menu.
Actions actions = new Actions(driver);
actions.moveToElement(element).perform();
Right Click
Perform a context-click using Selenium Actions.
actions.contextClick(element).perform();
Double Click
Perform a double click and validate the resulting action.
actions.doubleClick(element).perform();
Drag & Drop
Drag an object from the source area and drop it into the target.
actions.dragAndDrop(source, target).perform();
Click & Hold
Hold the mouse button on the target and release it to complete the action.
actions.clickAndHold(element).perform();
actions.release().perform();
Move To Element
Move the mouse pointer to a specific element.
actions.moveToElement(element).perform();
Selenium Actions Class
Actions actions =
new Actions(driver);
actions
.moveToElement(element)
.perform();
actions
.contextClick(element)
.perform();
actions
.doubleClick(element)
.perform();
actions
.dragAndDrop(source, target)
.perform();
actions
.clickAndHold(element)
.perform();