How to make protractor press the enter key?

JavascriptAngularjsProtractor

Javascript Problem Overview


I've tried this:

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

which gives the error:

Error: Not a modifier key

Javascript Solutions


Solution 1 - Javascript

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 - Javascript

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 - Javascript

Here is another way of doing this

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

Solution 4 - Javascript

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

Solution 5 - Javascript

this will work fine try it

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

Solution 6 - Javascript

In my case enter click did not performe without sleep() between typed text and Enter click.

const someInput = $('#someInput');
someInput.sendKeys('test text');
browser.sleep(1000);
someInput.sendKeys(protractor.Key.ENTER);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbodineView Question on Stackoverflow
Solution 1 - JavascriptJmrView Answer on Stackoverflow
Solution 2 - JavascriptAndres DView Answer on Stackoverflow
Solution 3 - JavascriptpatzView Answer on Stackoverflow
Solution 4 - JavascriptjfountainView Answer on Stackoverflow
Solution 5 - Javascriptbhargava krishnaView Answer on Stackoverflow
Solution 6 - JavascriptIhor KhomiakView Answer on Stackoverflow