Sanju
Sanju

Reputation: 1518

How to perform Control+Click on a multi-select option in protractor?

I'm trying to click on multiple selections in a multi select box. But I'm unable to perform the same.

What i have tried so far:

let input = $('input');
let option1 = input.all(by.cssContainingText('option','One'));
let option2 = input.all(by.cssContainingText('option','Two'));
option1.click();
browser.actions().mouseMove(option2).keyDown(protractor.Key.CONTROL).click().perform();

This solution is based on this answer but it throws an error: unknown error: at least an element or offset should be set. It also shows Promise rejection was handled asynchronously in browser.pause() logs while the click event is invoked.

Any help would be appreciated!

Upvotes: 0

Views: 1321

Answers (1)

Sanju
Sanju

Reputation: 1518

I have managed to solve this issue. For some reason the method I used to select options were not working. So I modified the code to use element based locator in a different way.

let options = $$('multiselect-dropdown option');
options.get(0).click();
browser.actions()
    .mouseMove(options.get(1))
    .keyDown(protractor.Key.CONTROL)
    .click()
    .keyUp(protractor.Key.CONTROL)
    .perform();

Now everything's working fine.

Upvotes: 2

Related Questions