Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do a Ctrl+Click on protractor?

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();
like image 223
Chexpir Avatar asked Jan 07 '15 17:01

Chexpir


1 Answers

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.

like image 140
alecxe Avatar answered Oct 02 '22 05:10

alecxe