Search code examples
javascriptangularjsnode.jsprotractorend-to-end

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();

Solution

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