6

I have tried weird combination as the following, but none of them are working:

var ptor = protractor.getInstance();
ptor.actions().mouseMove(node).keyDown(ptor.Key.CTRL).sendKeys(ptor.Key.CLICK).perform();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Chexpir
  • 1,876
  • 18
  • 33

1 Answers1

14

You need to chain mouseMove(), keyDown() and click():

var elm = element(by.id('my_id'));

browser.actions()
    .mouseMove(elm)
    .keyDown(protractor.Key.CONTROL)  // COMMAND for Mac 
    .click()
    .perform();

Tested it on Chrome by clicking on a link - opens up a link in a new tab.


Note that, starting with protractor 1.5, there is a global browser object that should be used instead of protractor.getInstance(), see Breaking Changes.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thank you! As a comment, in protractor 1.2, CTRL key throws the following error (- Error: Not a modifier key) and SHIFT key works correctly. protractor.getInstance().actions().mouseMove(node).keyDown(protractor.Key.SHIFT).click().perform(); – Chexpir Jan 08 '15 at 10:05
  • 1
    @Chexpir FYI the CTRL key (under Windows) is named protractor.Key.CONTROL – jmcollin92 Sep 04 '15 at 14:39