8

I know that protractor click on element by default with left mouse button. How to do it to click with RIGHT MOUSE BUTTON ?

el.click('RIGHT'); ?

Sanoob
  • 2,466
  • 4
  • 30
  • 38
georgw
  • 83
  • 1
  • 1
  • 3

3 Answers3

20

I would have done like this:

browser.actions().mouseMove(el.find()).perform();
browser.actions().click(protractor.Button.RIGHT).perform();

Based on what I saw in actionsequence.js and Protractor rightClick issue #280

glepretre
  • 8,154
  • 5
  • 43
  • 57
  • The browser.actions() way seems to have broke in protractor 2.0? – Klas Mellbourn Apr 14 '15 at 08:30
  • @KlasMellbourn If there is a breaking change, it should come from Webdriver which has been upgraded in Protractor 2.0. Have you seen its changelog? I'll take a look too. You can also open an issue on Protractor GitHub ;) – glepretre Apr 14 '15 at 12:08
  • @glepretre I have now raised this issue https://github.com/angular/protractor/issues/2043 – Klas Mellbourn Apr 14 '15 at 14:05
  • I got `el.find is not a function`. Had to use `el.getLocation()` instead, but otherwise this worked. – hughes Oct 10 '16 at 21:34
2

The accepted solution for this question isn't the best way to go about this. Browser actions' .click() method accepts an optional arg for clicking the right button. A better solution, from the webdriverJs api is:

browser.actions()
    .click($('.myElm'), protractor.Button.RIGHT)
    .perform();
Brine
  • 3,733
  • 1
  • 21
  • 38
-2

Try this:

el.sendKeys(protractor.Key.RIGHT)

Here is the list of keys: https://code.google.com/p/selenium/source/browse/javascript/webdriver/key.js

If it doesn't work do this: https://groups.google.com/forum/#!topic/selenium-users/fF_Hcp40KO0

Let me know if it works

Andres D
  • 8,910
  • 2
  • 26
  • 31
  • 3
    I think that `protractor.Key.RIGHT` performs a right arrow keypress, am I wrong? – glepretre Mar 17 '14 at 11:15
  • In Protractor 5.4.2 version with Jasmine , below code is no longer working . Could you please suggest something else since it does nothing ? Thank you . browser.actions().mouseMove(el.getLocation()).perform(); browser.actions().click(protractor.Button.RIGHT).perform(); – Sameera De Silva Dec 17 '19 at 12:20