-
Actionis an interface in Selenium.
It represents a single user interaction such as a mouse click, key press, or drag-and-drop operation. -
Actionsis a class in Selenium that is used to build and perform complex user interactions (a chain of actions).
It provides methods likeclick(),doubleClick(),moveToElement(),keyDown(), etc., which can be chained together to create a sequence of actions.
Actions usage:
WebElement element = driver.findElement(By.id(“menu”));
// Create an instance of Actions class
Actions actions = new Actions(driver);
// Build and perform a chain of actions
actions.moveToElement(element)
.click()
.doubleClick()
.contextClick()
.perform(); // Executes the built chain directly
Action usage:
// Create an instance of Actions class
Actions actions = new Actions(driver);
// Build a chain of actions and store it as an Action object
Action hoverAndClick = actions.moveToElement(element)
.click()
.build(); // returns an Action object
// Perform the built action
hoverAndClick.perform();