Let me explain the code here.....
If you want to right click on any element then selenium doesn't provide any direct method for that. We need to use Actions class provided by WebDriver. The Actions class provided by Selenium Webdriver is used to generate complex user gestures including right click, double click, drag and drop etc.
Here is the code:-
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.id("elementId"));
Here, we are instantiating an object of Actions class. After that, we pass the WebElement to be right clicked as parameter to the contestClick() method present in the Actions class. Then, we call the perform() method to perform the generated action.
Hope this will help you...