im trying to preform a right click using selenium, any thoughts on how to do this?
Asked
Active
Viewed 3.4k times
14
-
3What have you done yourself? Or do you want people to do all the work for you? – Cromulent Jan 31 '10 at 12:11
-
possible duplicate of [JavaScript simulate right click through code](http://stackoverflow.com/questions/433919/javascript-simulate-right-click-through-code) – Felix Kling Sep 26 '11 at 19:50
-
Possible duplicate of [JavaScript simulate right click through code](https://stackoverflow.com/questions/433919/javascript-simulate-right-click-through-code) – Liam Sep 19 '18 at 08:15
5 Answers
12
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();

Bleeding Fingers
- 6,993
- 7
- 46
- 74

Peter Agnew
- 361
- 3
- 3
4
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.

Community
- 1
- 1

Felix Kling
- 795,719
- 175
- 1,089
- 1,143
-
-
1I would delete this answer, but I cannot, since it is the accepted one. – Felix Kling Aug 17 '12 at 12:41
-
Appreciate the openness, but it probably isn't worth fussing with now. – Marc Gravell Aug 17 '12 at 13:02
-
@Marc: You are probably, but I got an upvote for the answer, had a look at it and wanted to set things straight :) My comment was actually not directed at you, but just a general remark for any reader. – Felix Kling Aug 17 '12 at 13:11
2
it appears that for my issue (an element that opens a popup after a right click), using selenium's : mouse_down_right() and then mouse_up_right() worked as well. thanks.

doctoroots
- 189
- 1
- 1
- 6
2
Selenium is offering a method for right click - ContextClick:
public void RightClick(IWebElement target)
{
var builder = new Actions(driver);
builder.ContextClick(target);
builder.Perform();
}

P.Petkov
- 1,569
- 1
- 12
- 20
1
I've tried ActionSequence and it worked.
ContextClick function is not found, you should use click.
So, it should be as follows:
driver.actions().click(element,2).perform();
The element is your web element, 2 means right click.

Mr. Xcoder
- 4,719
- 5
- 26
- 44

Luna007
- 11
- 1