14

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

doctoroots
  • 189
  • 1
  • 1
  • 6
  • 3
    What 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 Answers5

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
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