Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 844
bodine Avatar asked Nov 11 '13 20:11

bodine


3 Answers

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

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

like image 188
Jmr Avatar answered Nov 07 '22 14:11

Jmr


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);
like image 80
Andres D Avatar answered Nov 07 '22 13:11

Andres D


Here is another way of doing this

var enter = browser.actions().sendKeys(protractor.Key.ENTER);
enter.perform();
like image 10
patz Avatar answered Nov 07 '22 14:11

patz