How to make protractor press the enter key?

I've tried this:

browser.actions().keyDown(protractor.Key.ENTER).keyUp(protractor.Key.Enter).perform();

which gives the error:

Error: Not a modifier key

Solution 1:

Keyup/Keydown is limited to modifier keys in WebDriver (shift, ctrl, etc). I think you want

browser.actions().sendKeys(protractor.Key.ENTER).perform();

Solution 2:

The actions() is not required.

You can do something like:

var input = $('#someInput');
input.sendKeys(protractor.Key.ENTER);

Update: some people have complained that you are not sending the enter to browser. If you want to do this just change your selector:

$('body').sendKeys(protractor.Key.ENTER);

Solution 3:

Here is another way of doing this

var enter = browser.actions().sendKeys(protractor.Key.ENTER);
enter.perform();

Solution 4:

From the docs here...

http://appfigures.github.io/webdriver-js-api-reference/symbols/webdriver.WebElement.html#sendKeys

var myInput = element(by.model('myModel.inputName'));
myInput.sendKeys(value, protractor.Key.ENTER);

Also other examples from the docs linked above.

myInput.sendKeys("text was",
                 protractor.Key.CONTROL, "a", protractor.Key.NULL,
                 "now text is");
// Alternatively:
myInput.sendKeys("text was",
                 protractor.Key.chord(protractor.Key.CONTROL, "a"),
                 "now text is");