Mouse Hover and Drag Drop Action in Selenium WebDriver

Posted By : Neha Dahiya | 28-May-2018

Mouse Hover:

Special mouse and keyboard events can be handled using Advanced User Interactions API which contains Action class needed to execute these events.

Firstly we have to identify elements which we want to hover and then with the help of Action class, move over an element action can be performed.

Step 1: Import the Actions class.

import org.openqa.selenium.interactions.Actions;

Step 2: Instantiate a new Actions object.

Actions act = new Actions(driver);

Step 3: Use perform() method which is used to execute the action.

Actions act = new Actions(driver);

act.moveToElement(element).perform();

Find the code below to perform Mouse over an element.

 
 
 

Drag and Drop:

A predefined method dragAndDrop(source, destination), a method of Actions class.

Step 1: Find XPath of both source and destination.

Step 2: Use perform() method which is used to execute the action.

Find the code below to perform Drag and Drop Action

 

Thanks!!

Related Tags

About Author

Author Image
Neha Dahiya

Neha is a bright QA Engineer with skills in manual testing . Apart from finding bugs in application, she loves sketching and painting.

Request for Proposal

Name is required

Comment is required

Sending message..