Perform a sequence of actions with Selenium WebDriver

4.6 (91.09%) 119 votes


We want to perform multiple actions in once, like: drag-and-drop, sliding, selecting multiple items.


The example code below shows some examples where we can use the Actions interface of Selenium WebDriver.

<code lang="java">
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class ActionExample {
    private static WebDriver driver;

    public void setUp() {
        driver = new FirefoxDriver();

    public void tearDown() {

    public void draggable() {

        WebElement draggable = driver.findElement("draggable"));
        new Actions(driver).dragAndDropBy(draggable, 120, 120).build()

    public void droppable() {

        WebElement draggable = driver.findElement("draggable"));
        WebElement droppable = driver.findElement("droppable"));
        new Actions(driver).dragAndDrop(draggable, droppable).build().perform();

    public void selectMultiple() throws InterruptedException {

        List&lt;WebElement> listItems = driver.findElements(By
                .cssSelector("ol#selectable *"));

        Actions builder = new Actions(driver);

        Action selectMultiple =;

    public void sliding() {

        WebElement draggable = driver.findElement(By
        new Actions(driver).dragAndDropBy(draggable, 120, 0).build().perform();

3 thoughts on “Perform a sequence of actions with Selenium WebDriver”

  1. hi i have one question using selenium web driver how to select buttons in sequence vice means i have 10 buttons in list with same name how to select those buttons one by one

    1. get all the buttons using xpath = //***button
      Save to a List using findElements(by.xpath(“”))
      Iterate and click based on the total size of list

  2. hello ,
    Getting error at line:
    Error is multiple markers at the line. List item can not be resolved.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.