How to perform right click operation in selenium web driver using java

KeyPoints for the task

 Create an object of Actions class.

Actions action = new Actions(driver);

Call the method to perform an action.

action.contextClick(“Name of the element”).perform();

Task Scenario:

  •  Open browser.
  • Load the URL “”.
  • Right click on the logo of the home page.

Automate mouse events (Right click) in selenium web driver with an example.


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class RightClick {
public static void main(String[] args) {
System.setProperty("", "D:\\Automation\\chromedriver_win32\\chromedriver.exe");
// Open Browser
WebDriver driver = new ChromeDriver();
// Launching web site URL to automate.
// Pass the driver object to the Action class.
Actions action = new Actions(driver);
// Find the element by id or xPath its up to you.
WebElement siteLogo = driver.findElement("site-name"));
// Pass the element to contextClick method and perform operation using object of
// action class.
// Close browser.

// driver.close();