Right Click and Double Click in Selenium
โก Smart Summary
Right Click and Double Click in Selenium are mouse actions automated through the Actions class. This tutorial demonstrates both operations with working Java code, real test scenarios, and the methods that drive them inside Selenium WebDriver.

Right Click in Selenium
Right click action in Selenium WebDriver is done using the Actions class. The operation is also called Context Click. The predefined contextClick() method of the Actions class performs the right click. Below is the basic syntax.
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.contextClick(elementLocator).perform();
How to Right Click in Selenium
The scenario below launches a Guru99 demo page, performs a right click, and selects an option from the context menu that appears.
Test Scenario:
- Launch: https://demo.guru99.com/test/simple_context_menu.html
- Right Click on the button “right click me”
- Click the Edit link on the displayed menu
- Click OK on the alert
- Close the browser
Code:
package test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class ContextClick {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "X://chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://demo.guru99.com/test/simple_context_menu.html");
driver.manage().window().maximize();
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.cssSelector(".context-menu-one"));
action.contextClick(link).perform();
WebElement element = driver.findElement(By.cssSelector(".context-menu-icon-copy"));
element.click();
}
}
Result: The context menu appears and the Edit option is selected.
Double Click in Selenium
Following the same Actions-based pattern, Double Click in Selenium WebDriver uses the predefined doubleClick() method. The Actions class is the standard helper for compound mouse and keyboard operations such as Right Click, Drag and Drop, and Hover.
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.doubleClick(elementLocator).perform();
The execution flow is:
- Instantiate an Actions object using the driver instance.
- Locate the target element with
findElement. - Call
doubleClick()and chainperform()to execute.
How to Double Click in Selenium
The next scenario demonstrates a full double click that triggers a JavaScript alert and confirms it programmatically.
Test Scenario:
- Launch: https://demo.guru99.com/test/simple_context_menu.html
- Double click the button “Double-Click Me To See Alert”
- Click OK on the alert
Code:
package test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.Alert;
public class DoubleClickDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "X://chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://demo.guru99.com/test/simple_context_menu.html");
driver.manage().window().maximize();
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.xpath("//button[text()='Double-Click Me To See Alert']"));
action.doubleClick(link).perform();
Alert alert = driver.switchTo().alert();
System.out.println("Alert Text\n" + alert.getText());
alert.accept();
}
}
Result: The alert pops up and the alert text is printed to the Eclipse console.



