Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can you do right click using selenium?

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

like image 549
doctoroots Avatar asked Jan 31 '10 12:01

doctoroots


People also ask

Which class is used for right click in Selenium WebDriver?

For right clicking an element in Selenium, we make use of the Actions class. The Actions class provided by Selenium Webdriver is used to generate complex user gestures including right click, double click, drag and drop etc.

How would you perform right click or double click using WebDriver?

In this video, we will be using actions class for advanced activity. We will use contextClick method for right click and doubleClick method double click activity. Actions Class link.

What are the various ways of click in Selenium?

Alternative of click() in Selenium We can use the JavaScript Executor to perform a click action. Selenium can execute JavaScript commands with the help of the executeScript method. The parameters – arguments[0]. click() and locator of the element on which the click is to be performed are passed to this method.


2 Answers

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();
like image 87
Peter Agnew Avatar answered Oct 21 '22 19:10

Peter Agnew


Please see docroots's answer for selenium.

To generally simulate a right click in JavaScript, have a look at JavaScript simulate right click through code.

like image 25
Felix Kling Avatar answered Oct 21 '22 19:10

Felix Kling