how can you do right click using selenium?

doctoroots picture doctoroots · Jan 31, 2010 · Viewed 32.3k times · Source

im trying to preform a right click using selenium, any thoughts on how to do this?

Answer

Peter Agnew picture Peter Agnew · Oct 1, 2013

According to the OpenQA.Selenium.Interactions Namespace.

// step 1 - select the element you want to right-click
var elementToRightClick = this.Driver.FindElement(By.Id("elementtoclickonhasthisid"));
// step 2 - create and step up an Actions object with your driver
var action = new OpenQA.Selenium.Interactions.Actions(this.Driver);
action.ContextClick(elementToRightClick);
// step 3 - execute the action
action.Perform();